Spread Operator
Added in ES 2015
The array spread operator is symbolized with three dots ( ... )
Combining Arrays
const myArray1 = ['mon', 'tue']
const myArray2 = ['wed', 'thu', 'fri']
const myArray3 = [...myArray1, ...myArray2]
Using array destructuring (added in ES 2015)
const myArray2 = ['wed', 'thu', 'fri']
var [firstItem, ...remainingItems] = myArray2
console.log(remainingItems);
This operator converts an array to a list of items.
const myArray = ['mon', 'tue', 100]
const newArray = [...oldArray];
Passing a list of arguments to a function
You can also use the spread operator to collect function arguments as an array.
const myArguments = ['arg1', 'arg2', 100]
myFunction(...myArguments);
function myFunction1(text1, text2, number1) {
}
this could also be done using array destructuring
© 2023 Better Solutions Limited. All Rights Reserved. © 2023 Better Solutions Limited TopPrevNext