Copying of an array of objects to another Array without object reference in javascript(Deep copy)

后端 未结 7 482
说谎
说谎 2020-12-01 05:05

I have a scenario where i need to copy the array of Objects(Main array) to another Temp array which should not have object reference basically if i make any modification to

相关标签:
7条回答
  • 2020-12-01 05:56

    Lodash can be used for deep copying objects _.cloneDeep(value)

    var objects = [{ 'a': 1 }, { 'b': 2 }];
    
    var deep = _.cloneDeep(objects);
    console.log(deep[0] === objects[0]);
    // → false
    
    0 讨论(0)
提交回复
热议问题