数组方法

47 阅读1分钟

静态方法

// 将类数组转换为数组
Array.from

// 判断是不是数组
Array.isArray

// 将一组数值转换为数组
Array.of
const a = Array.of(2,4,6,8);
console.log(a);         // \[2,4,6,8]

操作方法

影响原数组
push添加数据,在末端
unshift添加数据,在前端
pop删除最后一个值
shift删除第一个值
splice添加,修改,删除
reverse逆序
sort排序
不影响原数组
slice截取
join数组转字符串
concat拼接
indexOf根据内容查找索引
lastindexOf根据内容查找索引
includes判断数组是否包含相应内容
————
遍历
forEach标准遍历
map映射
filter过滤,筛选
reduce聚合
find查找
findindex查找索引
some只要一个满足则 true
every所有满足则 true
flat抹平