国产探花免费观看_亚洲丰满少妇自慰呻吟_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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 成安县| 丹寨县| 淳安县| 安义县| 胶州市| 石景山区| 潞西市| 大田县| 盘山县| 屏山县| 阳曲县| 陈巴尔虎旗| 玛纳斯县| 新营市| 定结县| 务川| 平南县| 清徐县| 墨玉县| 工布江达县| 巨野县| 满城县| 兰考县| 辰溪县| 长葛市| 宜春市| 昌乐县| 固始县| 绍兴县| 循化| 大竹县| 康马县| 茂名市| 邻水| 合川市| 绥棱县| 苍溪县| 沧州市| 石台县| 余干县| 广水市|