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

Hello,
Could you plz tell me why it does not pass my code while the output displayed in console is correct?
const arr1 = [‘JAN’, ‘FEB’, ‘MAR’, ‘APR’, ‘MAY’];

let arr2;

arr2 = ;

arr2.push(arr1); // Change this line

console.log(arr2);

Your code so far

const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
let arr2;

arr2 = [];
arr2.push(...arr1); // Change this line

console.log(arr2);

here s the question:
Copy all contents of arr1 into another array arr2 using the spread operator.

Thanks
sara

Your code so far

const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
let arr2;

arr2 = [];
arr2.push(...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/104.0.0.0 Safari/537.36

Challenge: ES6 - Use the Spread Operator to Evaluate Arrays In-Place

Link to the challenge:

You weren’t supposed to use push. The instructions were:

Copy all contents of arr1 into another array arr2 using the spread operator.

What you did was, create an empty array, use the spread operator to create a copy, then push that onto the created array. Those are a few extra steps. True, it does accomplish the same thing, but it does it in a way that is not compatible with the way the test is written - the test cannot account for everything.

Don’t use push, just do it all on one line.

1 Like