文章目录
1.forEach()
<script>
var arr=["a","s","d","f"];
arr.forEach(function(a,b,c){
console.log(a+" "+b+" "+c);
});
</script>
2.slice()和splice()
2.1 slice()
<script>
var arr=["a","s","d","f"];
var arr1=arr.slice(0,2);
console.log(arr1);
</script>
2.2splice()
<script>
var arr=["a","s","d","f"];
var arr1=arr.splice(1,2);
console.log(arr)
console.log(arr1);
</script>
3.数组去重
4.数组的其他函数
4.1 concat()
4.2 join()
4.3 reverse()
4.4 sort()
var arr=[3,4,11,2,5];
arr.sort();
console.log(arr)
var arr=[3,4,11,2,5];
arr.sort(function(a,b){
//升序
//return a-b;
//降序
return b-a;
});
alert(arr);