JS: Does Object.assign() create deep copy or shallow copy

后端 未结 7 1103
粉色の甜心
粉色の甜心 2020-11-30 03:21

I just came across this concept of

var copy = Object.assign({}, originalObject);

which creates a copy of original object into the \"

7条回答
  •  Happy的楠姐
    2020-11-30 04:14

    By using Object.assign(), you are actually doing Shallow Copy of your object. Whenever we do an operation like assigning one object to other, we actually perform a shallow copy, i.e. if OBJ1 is an object, modifying it through another object which is OBJ2 will reflect changes in OBJ1 too.

提交回复
热议问题