最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

javascript數組克隆簡單實現方法

 更新時間:2015年12月16日 09:44:44   作者:hongweigg  
這篇文章主要介紹了javascript數組克隆簡單實現方法,實例分析了JavaScript中concat用于數組克隆的使用技巧,需要的朋友可以參考下

本文實例講述了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程序設計有所幫助。

相關文章

最新評論

农安县| 门源| 元朗区| 巴楚县| 汽车| 鄱阳县| 桃源县| 塔城市| 鹤壁市| 陕西省| 桐庐县| 桃园市| 小金县| 石狮市| 广西| 波密县| 朔州市| 庆城县| 普安县| 耒阳市| 临泉县| 黔西县| 密山市| 甘南县| 和静县| 高雄市| 正蓝旗| 南岸区| 贡嘎县| 平湖市| 金乡县| 巴马| 乌鲁木齐市| 沙雅县| 泸定县| 阜宁县| 亳州市| 南江县| 界首市| 江陵县| 许昌市|