SoFunction
Updated on 2025-03-01

Introduction to common methods of cloning objects and arrays by js

Two cloning methods for Ext:

You can clone objects, data, etc.: var newJson = (json);
Only arrays can be cloned: var newJson = (json);

JQuery's method:

Deep copy [can be iterated]: var newJson = (true,{}, json);
Shallow copy [cannot iterate]: var newJson = ({}, json);

var newJson = $.map(json,function (n) { return n; });

Cloning method of array:
Copy the codeThe code is as follows:

var newJson = ();
var newJson = (0);


The above methods are to copy a new object or array, but if you directly use parent [iframe situation] to get the object of the parent window, there will be a problem [there is a reference relationship]. It should be noted that the method of fetching can be changed to the method of passing data.