Help with using the spread operator in js challenge

Tell us what’s happening:
What should I do?

Your code so far

function copyMachine(arr, num) {
let newArr = [];
while (num >= 1) {
  // Only change code below this line
newArr.num = [...arr];
  // Only change code above this line
return newArr;

console.log(copyMachine([true, false, true], 2));

Your browser information:

User Agent is: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0.

Challenge: Copy an Array with the Spread Operator

Link to the challenge:

Hi @amejl172!

I edited you post title to remove the link and replace it with a more descriptive title.

You will get more responses to your posts if you avoid placing links in the title.


Thanks for helping me with that.

So the issue is here.

The whole reason why we are using the spread operator to copy the array in the first place is to add that to the newArr. Right?

So there is helpful array method you can use that adds elements to an array.


Is newArr.num the only thing I need to change in the code?


You got the spread operator right but the first part is wrong.

1 Like

Should I use some kind of .slice() or .splice() method in this challenge?

they don’t seem necessary. how do you add new elements to an array?

1 Like

push or unshift.


Those sound good to me.


It worked, thanks for the help both of you.

1 Like