Basic Data Structures: Combine Arrays with the Spread Operator

Using spread syntax, we have just achieved an operation that would have been more complex and more verbose had we used traditional methods.

When I try to use the traditional method and try to copy one array into another like this:

let thisArray = ['sage', 'rosemary', 'parsley', 'thyme'];

console.log("thisArray before thatArray: " + thisArray)

// Old way
let thatArray = ['cilantro',thisArray.slice(0,3),'coriander']

console.log("thatArray: " + thatArray)

So, how does it is different from let thatArray = ['basil', 'cilantro', ...thisArray, 'coriander']; ?

And how the modern way(spread operator) is better than the traditional version(slice, as both OUTPUT the same result)?

Using the spread operator is less verbose and less complex, just as the lesson indicates.

Hi @pamnanaimanish169

“spread operator” unpack the whole array and with “slice” method here we have flexibility to slice array from any index to any index we want

spread operator - https://codeburst.io/javascript-es6-the-spread-syntax-f5c35525f754