var array = [0,1,2,3,4];
一:遍历方法
1.forEach:
array .forEach(function(v, i){.......}) // undefined
2.map:
array .map(function(v, i){ return v}) // [0,1,2,3,4]
3.filter:
array.filter(function(v, i){ return v}) // [1,2,3,4]
4.every:
array.every(function(v, i){ return v > 0}) // false
5.some:
array.some(function(v, i){ return v > 0}) // true
6.reduce:
array.reduce(function(v0, v1){ return v0 + v1}) // 10
二:其他
1.pop/push
array.pop() // 4 -----array=[0,1,2,3]
array.push(9) // 6 -----array=[0,1,2,3,4,9]
2.shift/unshift
array.shift() // 0 -----array=[1,2,3,4]
array.unshift(9) // 6 -----array=[9,0,1,2,3,4]
3.indexOf/lastIndexOf
array.indexOf(1) // 1
array.lastIndexOf(1) // 1
4.find/findIndex/include
5.reverse
array.reverse() // [4,3,2,1,0]
6.splice
array.splice(2, 1, "William") // [2] -----array = [0,1,"william",4]
7.concat
[1].concat(1,2) // [1, 1, 2]
[1].concat([1,2]) // [1, 1, 2]
8.sort
var array1 = ["George", "John", "Thomas", "James", "Adrew", "Martin"]
var array2 = [1, 9, 8]
array1.sort() //Adrew,George,James,John,Martin,Thomas
array2 .sort(function(a,b){return a -b}) // [1,8,9]
9.fill