Link Search Menu Expand Document

Copy an Array with the Spread Operator

Summary

  • Spread syntax (...myArray) allows an entire array to be copyed.

Final Code

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

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