- 增:
push(item1, item2...)
: 末尾插入 […, item1, item2… ]
unshift(item1, item2, ...)
: 开头插入 [ item1, item2… , …]
splice(startIndex, ?deleteCount, item1, item2...)
: 任意位置
concat(?item, ?Array)
: 末尾插入, 返回数组副本 - 删:
pop()
: 删除数组末尾元素,并返回
shift()
: 删除数组首部元素,并返回
slice(startIndex, ?endIndex)
: 删除指定区域元素
splice(startIndex, ?deleteCount)
: 删除指定区域开始的指定个数个元素,并以列表形式返回被删除的元素。deleteCount大于剩余元素时,保留startIndex前的元素。 - 改
splice(startIndex, ?deleteCount, item1, item2...)
- 查
[index]
: 越界返回undefine
indexOf(item, ?startIndex)
: 从头开始找,未找到返回-1
lastIndexOf(item, ?startIndex)
: 从末尾开始找, 未找到返回-1 - 遍历
for循环
for(let item of array) { }
: 可以正常响应continue
,break
,return
,item无法修改原数组
forEach( (item, index) => { } )
: 无法响应continue
,break
,return
,item无法修改原数组 - 一些常用方法
map((value, index, array)=>{})
filter((value, index, array)=>{})
reduce((pre, curr, index, array)=>{}, initValue)
reduceRight((pre, curr, index, array)=>{}, initValue)
find((value, index, array)=>{ return 布尔值 })
findIndex((value, index, array)=>{ return 布尔值 })
keys()
,values()
,entries()
: 返回迭代器对象
javascript 数组的增删改查、遍历与常用方法
猜你喜欢
转载自blog.csdn.net/SJ1551/article/details/109295038
今日推荐
周排行