原型 - flatten() 方法
此方法返回一个扁平(一维)的数组版本。嵌套数组会递归地注入到单行内。
在处理递归集合算法的结果时,此功能非常有用。
语法
array.flatten();
返回值
返回一个扁平的(一维)数组。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
var arr =['frank',['bob','lisa'],['jill',['tom','sally']]];
// Now flatten this array.
var newArr = arr.flatten();
newArr.each(function(item) {
alert(item);
});
}
</script>
</head>
<body>
<p>Click the button to see the result.</p>
<br />
<br />
<input type = "button" value = "Result" onclick = "showResult();"/>
</body>
</html>
输出
prototype_array_processing.htm
广告