Help - Use the Spread Operator to Evaluate Arrays In-Place

Tell us what’s happening:

i am trying to copy the array into the new array, but i can’t figure out how to do it.

Your code so far


const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
let arr2;
(function(arr1) {
  "use strict";
  arr2 = [...arr1]; // change this line
})();
console.log(arr2);

Your browser information:

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

Link to the challenge:
javascript-algorithms-and-data-structures found is es6

Don’t pass arr1 into the IIFE definition:

because you are not providing it when you invoke the function

})();

thus you end up using the spread operator on undefined. If you don’t pass it in, arr1 in the expression [...arr1] points to the global variable on line 1 (which is why it has the only change this line comment). If you did want arr1 to be a parameter, you could pass it when the function is invoked.

const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
let arr2;
(function(arr1) {
  "use strict";
  arr2 = [...arr1]; // change this line
})(arr1);
console.log(arr2);

i understand now. i was trying to do too much. thank you!