返回到:Prototype – 数组处理
此方法返回数组的平面(一维)版本。嵌套数组以内联方式递归注入。
这在处理递归收集算法的结果时非常有用。
语法
array.flatten();
返回值
返回平面(一维)数组。
例子
HTML
x
26
26
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 arr =['frank',['bob','lisa'],['jill',['tom','sally']]];
9
10
// Now flatten this array.
11
var newArr = arr.flatten();
12
13
newArr.each(function(item) {
14
alert(item);
15
});
16
}
17
</script>
18
</head>
19
20
<body>
21
<p>Click the button to see the result.</p>
22
<br />
23
<br />
24
<input type = "button" value = "Result" onclick = "showResult();"/>
25
</body>
26
</html>
返回到:Prototype – 数组处理
阅读剩余 41%
作者:terry,如若转载,请注明出处:https://www.web176.com/prototype_api/8786.html