array.push()
数组推入一个元素,在末尾添加;直接执行这句话,直接改变array的内容。
array.pop()
数组抛出一个元素,从末尾删除
array.shift()
数组移除第一个元素
array.unshift()
数组在开头添加一个元素
array.map(function(currentValue,index,arr), thisValue)
返回一个新数组,数组中的元素为原始数组元素调用函数处理后的值。
newArray = oldArray.concat(otherArray);
concat 方法可以用来把两个数组的内容合并到一个数组中。
concat 方法的参数应该是一个数组。参数中的数组会拼接在原数组的后面,并作为一个新数组返回。
Math.max.apply(Math,array)
Math.min.apply(Math,array)
求数组的最大值和最小值
array.slice()
array.splice(start)
array.splice(start, deleteCount)
array.splice(start, deleteCount, item1, item2, ...)
splice() 方法通过删除现有元素和/或添加新元素来更改数组的内容。
筛选:
var new_array = arr.filter(callback[, thisArg])
callback
用来测试数组的每个元素的函数。调用时使用参数 (element, index, array)。
返回true表示保留该元素(通过测试),false则不保留。
thisArg
可选。执行 callback 时的用于 this 的值。
实例:
function isBigEnough(element) {
return element >= 10;
}
var filtered = [12, 5, 8, 130, 44].filter(isBigEnough);
数组排序:
array.sort();//不稳定性,按照Unicode编码排序;
array.sort(function(a,b){
return a-b;
});//数字排序,从小到大
把数组中的内容连接成字符串:
array.join("");
//与`array.split("");`相辅相成