国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

javascript數組克隆簡單實現方法

2019-11-20 11:00:27
字體:
來源:轉載
供稿:網友

本文實例講述了javascript數組克隆簡單實現方法。分享給大家供大家參考,具體如下:

<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>新建網頁 1</title></head><body><script language=javascript>var a = ['a','b','c','d','e','f'];var b = a.concat();b.push('test is ok!');alert(b.join(','));alert(a.join(','));</script></body></html>

武林網小編補充

The JavaScript
To clone the contents of a given array, all you need to do is call slice, providing 0 as the first argument:

var clone = myArray.slice(0);

The code above creates clone of the original array; keep in mind that if objects exist in your array, the references are kept; i.e. the code above does not do a "deep" clone of the array contents. To add clone as a native method to arrays, you'd do something like this:

Array.prototype.clone = function() {
return this.slice(0);
};

And there you have it! Don't iterate over arrays to clone them if all you need is a naive clone!

希望本文所述對大家JavaScript程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 桂林市| 弥渡县| 资源县| 巫山县| 从江县| 嘉禾县| 临邑县| 阿克陶县| 抚宁县| 安新县| 开化县| 玉山县| 荣成市| 义马市| 邢台县| 社旗县| 永定县| 攀枝花市| 龙州县| 安塞县| 商河县| 揭东县| 土默特右旗| 固阳县| 禹城市| 修武县| 宁南县| 沁水县| 普定县| 昆明市| 渭南市| 荆州市| 定兴县| 墨竹工卡县| 娱乐| 永兴县| 镇原县| 乌什县| 舞阳县| 天台县| 稷山县|