Found something interesting in spread opreator (...)

Tell us what’s happening:
Describe your issue in detail here.
while doing this challenge, i found that spread operator will help you to remove one array

Your code so far

let arr = [1,2,3,4,5];

console.log(...arr);  // 1 , 2 ,3, 4 , 5     *the array[] symbol gone
console.log(arr); // [1,2,3,4,5] 

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: Steamroller

Link to the challenge:

Yep, this is exactly the function of spread syntax. It takes an iterable (such as an array) and converts it into a “list”. In your example above, it takes the items out of an array and passes them in as separate arguments to console.log. So instead of having to call console.log as:

console.log(arr[0], arr[1], arr[2], arr[3], arr[4]);

You can do:


which is the same thing and will give you the same result.

Thank you for explaining in details

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.