Array.prototype.indexOf(value);得到值在数组中的第一个下标
Array.prototype.lastIndexOf(value);得到值在数组中的最后一个下标
Array.prototype.forEach(function(item,index){});遍历数组
Array.prototype.map(function(item,index){});遍历数组返回一个新的数组,返回加工之后的值
Array.prototype.filter(function(item,index){});遍历过滤出一个新的子数组,返回条件为true的值
代码如下:
<script>
var arr=[2,6,9,2,1,5,4];
console.log(arr.indexOf(2));//输出0
console.log(arr.lastIndexOf(2));//输出3
arr.forEach(function (item, index) {
console.log(item,index);
});
var arr1=arr.map(function (item,index) {
return item+10;
})
console.log(arr1);
var arr2=arr.filter(function (item, index) {
return item > 5;
})
console.log(arr2);
</script>
结果: