javascript / beginner
Snippet
The Spread Operator (Arrays)
The spread operator (...) allows an iterable such as an array to be expanded in places where zero or more arguments or elements are expected. It's a clean way to copy or combine arrays.
snippet.js
1
2
3
4
const fruits = ['apple', 'banana'];const moreFruits = [...fruits, 'orange', 'kiwi'];console.log(moreFruits);
nodejs
Breakdown
1
const moreFruits = [...fruits, 'orange', 'kiwi'];
Spreads the elements of 'fruits' into a new array and adds two more items at the end.
2
console.log(moreFruits);
Prints the combined array containing all four fruit strings.