1.Array对象元素的下标从0开始,基本操作,创建数组,遍历数组,删除数组元素,增加数组元素
代码:
<html>
<head>
<script type="text/javascript" src="jquery-3.2.1.min.js"></script>
<script type="text/javascript">
var str="";
var arr= new Array("a","b","d","e");
arr[4]="c";/*添加元素*/
for (var i=0;i<5;i++){
str=str+arr[i];
}
document.write(str);
delete arr[1];/*删除元素*/
document.write(arr);
</script>
</head>
<body>
<script type="text/javascript">
</script>
</body>
</html>
2.prototype属性
语法:
Array.prototype.name=value
name:要添加的属性名和方法名
value:添加属性的值或执行方法的函数
<html>
<head>
<script type="text/javascript" src="jquery-3.2.1.min.js"></script>
<script type="text/javascript">
Array.prototype.outLast=function(){
document.write(this[this.length-1]);
}
var arr=new Array(1,2,3,4,5,6,7,8);
arr.outLast();
</script>
</head>
<body>
<script type="text/javascript">
</script>
</body>
</html>