node.js - Assigning javascript object to new object as copy -


i have array of object obj.arr in javascript. assigned new object.

var obj_arr_new = obj.arr; 

the problem when modify obj_arr_new, obj.arr gets modified well. not want that. how can make obj_arr_new copy of obj.arr , when modify obj_arr_new, obj.arr untouched?

i using node.js v6. open using node.js module. told me lodash can job. answer using lodash helpful.

lodash indeed has _.clonedeep(value) purpose.

var obj_arr_new = _.clonedeep(obj.arr); 

it recursively clone "arrays, array buffers, booleans, date objects, maps, numbers, object objects, regexes, sets, strings, symbols, , typed arrays" modifying bits of clone doesn't affect original, or vice versa.

documentation


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -