JS Deep Clone Object
JS Deep Clone Object Simple record, the following code:
varobj ={typeOf:function(obj) {const toString=Object.prototype.toString; Const MAP= { ' [Object Boolean] ': ' Boolean ', ' [Object number] ': ' Number ', ' [Object string] ': ' String ', ' [Object function] ': ' function ', ' [Object array] ': ' Array ', ' [Object Date] ': ' Date ', ' [Object RegExp] ': ' RegExp ', ' [Object Undefined] ': ' Undefined ', ' [Object Null] ': ' null ', ' [Object Object] ': ' Object ' }; returnMap[tostring.call (obj)]; }, Deepcopy (data) {const T= This. typeOf (data); Let o, I; if(t = = = ' array ') {o= []; } Else if(t = = = ' object ') {o= {}; } Else { returndata; } if(t = = = ' array ') { for(Let i = 0; i < data.length; i++) {O.push ( This. Deepcopy (Data[i])); } } Else if(t = = = ' object ') { for(Iinchdata) {O[i]= This. Deepcopy (Data[i]); } } returno; }};
JS Deep Clone Object