DEV Community

Discussion on: How to Deep Clone an Array in JavaScript

Collapse
 
aloksdiptim profile image
alokz diptim! • Edited

This right here deep copies nested array too

    let cloneMatrix  = [];

    for(let m = 0; m < matrix.length; m++){
        cloneMatrix.push([...matrix[m]]);
    }
Enter fullscreen mode Exit fullscreen mode

It pushes into a new array with [...matrix[m]]