The spread operator is used to break apart items in things like arrays, strings, or objects into individual pieces. It's often used to copy or join arrays, or to pass the items in an array as separate arguments to a function.
# 1.0 Array
1.1 Copy an array:
Instead of modifying the original array, you can create a shallow copy of an array.
1.2 Concatenating arrays:
Using the spread operator, you can concatenate arrays easily without using .concat().
1.3 Adding elements to an array:
You can easily add new elements to an array using the spread operator.
# 2.0 Object
2.1 Copy an object:
2.2 Merging object:
The spread operator allows you to merge two or more objects. If there are conflicting properties, the properties of the object that appears later will overwrite the previous ones.
# 3.0 Function
3.1 Using Spread in Function Calls :
You can use the spread operator to pass an array as individual arguments to a function.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3