Home >Web Front-end >JS Tutorial >Introduction to common methods of cloning objects and arrays in js_javascript skills

Introduction to common methods of cloning objects and arrays in js_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:21:091432browse
Two cloning methods of Ext:

You can clone objects, data, etc.: var newJson = Ext.clone(json);
You can only clone arrays: var newJson = Ext. Array.clone(json);

JQuery method:

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

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

Clone method of array:
Copy code The code is as follows:

var newJson = json.concat();
var newJson = json.splice(0);


The above methods all copy a new one Object or array, but if you directly access the object of the parent window through parent [iframe situation], there will be problems [there is a reference relationship]. It should be noted that you can change the method of fetching to the method of passing data.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn