kaniosrn-j
5/11/2017 - 8:20 PM

Copy Array

Copy Array

        let original = [true, true, false, false, undefined, null];

        // slice
        let copy1 = original.slice(0);
        console.log(copy1);

        // spread operator
        let copy2 = [...original];
        console.log(copy2);

        // deep copying
        let deepAray = [['deepArray']];
        let shallowCopy = deepAray.slice(0);

        shallowCopy[0].push('This is another array');
        console.log(deepAray[0], shallowCopy[0]);