*excercise asks for array for arr2
dont think it is an array tho
[ ‘JAN’, ‘FEB’, ‘MAR’, ‘APR’, ‘MAY’ ]
Your code so far
const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
arr2 = [...arr1]; // Change this line
console.log(typeof arr2); //object
Your browser information:
User Agent is:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36
Challenge: Use the Spread Operator to Evaluate Arrays In-Place
Link to the challenge:
JS is weird that way, isn’t it
typeof returns “object” for an array.
If you want to test if something is an array use isArray().
oh. that is weird.
i also thought spread doesnt provide an array, or did i make it an array with the brackets?
You are correct, the spread syntax does not technically create an array, it “expands an iterable” in places where multiple arguments are expected, such as parameters being passed into a function or items being added to an array. By placing the square brackets around the spread syntax you are then putting the expanded result of the spread into an array.
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.