返回到:Prototype – 数组处理
此方法返回数组的副本,原数组保持不变。
语法
array.clone();
返回值
返回一个新的克隆数组。
例子
HTML
x
30
30
1
<html>
2
<head>
3
<title>Prototype examples</title>
4
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
5
6
<script>
7
function showResult() {
8
var oldArr = ['Sam', 'Justin', 'Andrew', 'Dan'];
9
var newArr = oldArr.clone();
10
alert("Guys in old Arr" );
11
12
oldArr.each(function(item) {
13
alert(item );
14
});
15
alert("Guys in new Arr" );
16
17
newArr.each(function(item) {
18
alert(item );
19
});
20
}
21
</script>
22
</head>
23
24
<body>
25
<p>Click the button to see the result.</p>
26
<br />
27
<br />
28
<input type = "button" value = "Result" onclick = "showResult();"/>
29
</body>
30
</html>
返回到:Prototype – 数组处理
阅读剩余 44%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8798.html