Nested Data Structures Flashcards

1
Q

Array shallow copy method

A

array.slice() or you can use […array]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Object shallow copy

A

Object.assign({}, obj)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Deep copy with plain objects (any object, including arrays, that only has primitives, arrays, and plain objects as elements.)

A

let serializedArr = JSON.stringify(arr);
let deepCopiedArr = JSON.parse(serializedArr);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Deep copy with objects

A

let deepCopy = {};

for (const key in obj) {
deepCopy[key] = […obj[key]]
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly