<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>mootools--Native: Array</title>
<script language="javascript" type="text/javascript" src="mootools-1.2-core-jm.js"></script>
<script language="javascript" type="text/javascript">
{
//forEach用法一
var arr = [1,2,3,4,5,6];
arr.forEach(function(e){
alert(e);
});
//forEach用法二
var arr = [1,2,3,4,5,6];
var obj = "hello!";
arr.forEach(function(e){
alert(e+'--'+this); //这里的 this指后面的 obj 对象
},obj);
//forEach用法三
function putElt(element, index, array) { //输出到页面
document.write("pos [" + index + "] in array (" + array + ") is " + element + '<br>');
}
[2, 5, 9].forEach(putElt);
//filter方法
var result = [1,2,3,4,5].filter(function(e){
return e > 3;
});
alert(result); //结果为4,5
//map方法
var result = [1,2,3,4,5].map(function(e){
return e + 'px';
});
alert(result);
//some方法
var result = [1,2,3,4,5].every(function(e){
return e > 3;
});
alert(result); //返回true
//extend 方法
var a = [1,2,3,4];
var b = [1,11,12];
a.extend(b);
alert(a);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>