VehiclesFashionRecipesBlogsHuntTravelsSportFunHandmadeITEducation
Mini-Games
x

x
zakruti.com » IT - Software » freeCodeCamp.org
Copying Arrays (deep and shallow) - Beau teaches JavaScript

Copying Arrays (deep and shallow) - Beau teaches JavaScript

FBTwitterReddit

video description

Rating: 4.0; Vote: 1
Shallow copy arrays using slice and the spread operator. Deep copy arrays using JSON.stringify. - Code: http://codepen.io/beaucarnes/pen/OWePwd?editors=0012 - Beau Carnes on
Date: 2022-03-14

Comments and reviews: 5


I used this array to test:
let deepArray = [true, undefined, false, null, [-freeCodeCamp-]];
JSON changed the undefined to null during the copy. But isn't best practice to define empty data as null rather than undefined? And you probably would be testing if the data was undefined before pushing it on to your array anyways. (Or at least you should be.)

reply

// arr = [1,2,3]
// arr2 = arr.map(x=>x)
// console.log(arr2);
// arr = [1,2,3]
// let arr2 = JSON.parse(JSON.stringify(arr))
// console.log(arr2)
// arr = [1,2,3]
// arr2= arr.slice(0);
// console.log(arr2)
// arr = [1,2,3]
// arr2= []
// for(let i = 0; i

reply

When copying array of json data into new array using speard operator it's muting original data. Speard operator fails over here. I used to resolve this issue by using lodash --
reply

your explanations really need some work. there has been a lack of clarity in at least half of your videos that i've watched so far
reply

Dude... I'm already loving you so much. I spent an hour racking my brains with this at work and now it's finally settled.
reply
Add a review, comment






Other channel videos