这篇文章主要整理了js上的数组方法,方法的兼容性。在这个过程中我体会到了温故而知新的乐趣。希望阅读这篇文章的你也会有收获。
Array.prototypes上的方法
打开控制台,输入console.dir(Array.prototype)
,我们能获取到数组原型链的方法。
copyWithin
demo
array.copyWithin(target,start,end)
描述
将数组从start到end索引的元素(不包含end)复制到target开始的索引位置(改变原数组)
方法 | 描述 | 用法or示例 | 返回值 | 兼容性 |
---|---|---|---|---|
copyWithin | 将数组从start到end索引的元素(不包含end)复制到target开始的索引位置(改变原数组) | array.copyWithin(target,start,end) | undefined | > chrome 45 |
| 方法 |描述| 用法or示例 | 返回值 |是否改变原数组|兼容性|参考|
| -------- | ----- | ---- | ---- |
| copyWithin |将数组从start到end索引的元素(不包含end)复制到target开始的索引位置(改变原数组)| array.copyWithin(target,start,end) | undefined |是| chrome 45| mdn |
| fill |给定value填充数组,start到end| array.fill(value,start,end) |填充后的数组|是|
| find|返回数组中第一个匹配fn函数中条件的值没有则返回undefined| array.find(0) | 234 |
| findIndex | array.findIndex(0) | 234 |
| lastIndexOf | array.lastIndexOf(0) | 234 |
| pop | $1 | 234 |
| push | $1 | 234 |
| reverse | $1 | 234 |
| shift | $1 | 234 |
| unshift | $1 | 234 |
| slice | $1 | 234 |
| sort | $1 | 234 |
| splice | $1 | 234 |
| includes | $1 | 234 |
| indexOf | $1600 | 5 |
| join | $12 | 12 |
| keys | $1 | 234 |
| entries | $1 | 234 |
| values | $1 | 234 |
| forEach | $1 | 234 |
| filter | $1 | 234 |
| flat | $1 | 234 |
| flatMap | $1 | 234 |
| map | $1 | 234 |
| every | $1 | 234 |
| some | $1 | 234 |
| reduce | $1 | 234 |
| reduceRight | $1 | 234 |
| toLocaleString | $1 | 234|
| toString | $1 | 234|
Array上的方法
项目 | 价格 | 数量 |
---|---|---|
isArray | $1600 | 5 |
from | $12 | 12 |
of | $1 | 234 |