var arr = [];数组
var arr = new Array()函数
Array.of(el1[,el2[...]]) //建立一个新数组实例
prototype
Array.from(arrayLike) //将类数组(相似数组的对象和可遍历的对象)转为真正的数组。
code
// ES5的写法 var arr1 = [].slice.call(arrayLike); // ES6的写法 let arr2 = Array.from(arrayLike);
Array.prototype.concat(arr1[,arr2..]) //合并两个或多个数组。不更改现有数组,而是返回一个新数组。
对象
Array.prototype.join(separator) //以separator(默认为逗号)拼接为字符串。
排序
Array.prototype.toString() //把数组转换为字符串,数组中的元素之间用逗号分隔。
递归
Array.prototype.fill(value[, start, end]) //用一个固定值填充[start,end)的元素。
索引
Array.isArray() //判断传递的值是不是一个 Array。
ip
Array.prototype.filter()文档
Array.prototype.map()
Array.prototype.reverse() //将数组中元素的位置颠倒。
Array.prototype.sort()
Array.prototype.reduce()
语法:arr.reduce(callback,[initialValue])
callback(accumulator,currentValue,currentIndex,array)
accumulator 上一次调用回调返回的值
currentValue 数组中正在处理的元素
currentIndex 数据中正在处理的元素索引
array 调用 reduce 的数组
initialValue [可选],用于第一次调用 callback 的第一个参数。
Array.prototype.some(callback) //执行一次 callback 函数,直到找到一个使得 callback 返回true。
Array.prototype.every(callback) //数组的全部元素是否都经过callback 函数。
Array.prototype.find(callback) //在数组中返回符合callback第一个元素的值。
Array.prototype.findIndex(callback)//返回数组中知足callback的第一个元素的索引。不然返回-1。
Array.prototype.includes(searchElement) //是否包含一个指定的值
Array.prototype.pop() //删除数组最后一个元素,并返回该元素的值。
Array.prototype.push() //增长元素到数组末尾。
Array.prototype.shift() //删除数组第一个元素。
Array.prototype.unshift() //增长元素到数组开头。
Array.prototype.slice(start,end) //返回[start,end)**浅拷贝**到一个新数组对象,**原数组不会被修改**。
Array.prototype.splice() //经过删除现有元素和/或添加新元素来更改一个数组的内容,**会直接对数组进行修改**。
array.splice(start)
array.splice(start, deleteCount)
array.splice(start, deleteCount, item1, item2, ...)
start : 若是超出了数组的长度,则从数组末尾开始添加内容;若是是负值,则表示从数组末位开始的第几位(从1计数)。
deleteCount : 若是 deleteCount 是 0,则不移除元素,这种状况下,至少应添加一个新元素;若是 deleteCount 大于start 以后的元素的总数,则从 start 后面的元素都将被删除(含第 start 位);若是deleteCount被省略,则其至关于(arr.length - start)。
item1, item2, ... :要添加进数组的元素
Array.prototype.map(callback)
Array.prototype.forEach(callback)
Array.prototype.entries() //返回一个新的Array Iterator对象,该对象包含数组中每一个索引的键/值对。
Array.prototype.keys() //返回一个新的Array迭代器,它包含数组中每一个索引的键。
Array.prototype.values() //返回一个新的 Array Iterator 对象,该对象包含数组每一个索引的值。
for (let index of ['a', 'b'].keys()) { //遍历键 console.log(index); } // 0 // 1 for (let elem of ['a', 'b'].values()) { //遍历值 console.log(elem); } // 'a' // 'b' for (let [index, elem] of ['a', 'b'].entries()) { //遍历键/值对 console.log(index, elem); } // 0 "a" // 1 "b"