Tell us what’s happening: Hi, first time posting, so feel free to correct me in anyways
So, this is the solution, but if I change the line newArr.push([…arr]); to newArr = newArr.push, I get an error saying: TypeError: newArr.push is not a function
So, what is wrong about my way of thinking? I see that I can’t assign the value of an array that way, but I don’t understand why! Thanks for your help!
Your code so far
function copyMachine(arr, num) {
let newArr = [];
while (num >= 1) {
// change code below this line
newArr.push([...arr]);
// change code above this line
num--;
}
return newArr;
}
// change code here to test different cases:
console.log(copyMachine([true, false, true], 2));
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36
.
Challenge: Copy an Array with the Spread Operator
Link to the challenge: