WebGL Tutorial
and more

Array方法分类索引

撰写时间:2024-03-17

最新修订:2024-03-17

Array的方法数量众多,为在使用过程中快速地找到相应方法,特此制作精细分类索引。

静态方法

分类说明返回值函数名称函数参数
测试是否数组BooleanisArrayvalue
创建数组拆解以创建ArrayfromarrayLike, mapFn, thisArg
从多个对象创建Arrayof...elements

实例方法

获取特定结果的方法

以下方法,可从数组中获取特定的结果。不会修改原数组。

分类说明返回值函数名称函数参数
获取元素获取元素Anyatindex
找到符合条件的第一个元素AnyfindcallbackFn, thisArg
找到符合条件的最后一个元素AnyfindLastcallbackFn, thisArg
获取索引值获取首次出现的索引值NumberindexOfelement, fromIndex
获取最后一次出现的索引值NumberlastIndexOfelement, fromIndex
找到符合条件的第一个元素的索引值NumberfindIndexcallbackFn, thisArg
找到符合条件的最后一个元素的索引值NumberfindLastIndexcallbackFn, thisArg
获取遍历器获取键值对遍历器Iteratorentries
获取键遍历器Iteratorkeys
获取值遍历器Iteratorvalues
获取字符串获取有分隔符的字符串Stringjoinseperator
获取累积结果每个元素均参与累积运算AnyreducecallbackFn, initialValue
获取数组合并数组Arrayconcatvalues
筛选数组元素ArrayfiltercallbackFn, thisArg
展平数组Arrayflatdepth
映射并展平数组ArrayflatMapcallbackFn, thisArg
映射数组ArraymapcallbackFn, thisArg
切割数组Arrayslicestart, end
反转元素次序ArraytoReversed
排序数组ArraytoSortedcompareFn
删除并添加元素ArraytoSplicedstart, deleteCount, ...items

concat, filter, flat, flatMap, map, slice, toReversed, toSorted, toSpliced等方法都会返回Array的一个实例,将它们列入此类,是因为它们不会修改原数组,仅在新数组中修改数据,并返回新的数组。

测试真假的方法

以下方法,用以测试是否存在特定的情况。

分类说明返回值函数名称函数参数
测试是否包含元素Booleanincludeselement, fromIndex
是否全部元素满足条件BooleaneverycallbackFn, thisArg
是否部分元素满足条件BooleansomecallbackFn, thisArg

更改原数组的方法

以下的方法,将更改原数组。

分类说明返回值函数名称函数参数
更改元素数值填充数组Arrayfillvalue, start, end
修改单个元素数值Arraywithindex, value
在数组内替换元素数值ArraycopyWithintarget, start, end
添加元素在末尾添加元素Numberpush...elements
在首部添加元素Numberunshift...elements
移除元素弹出最后一个元素Anypop
移除首个元素Anyshift
移除并添加元素删除并添加元素Arraysplicestart, deleteCount, ...items
更改元素排列次序原地反转元素次序Arrayreverse
原地排序ArraysortcompareFn

遍历数组

分类说明返回值函数名称函数参数
遍历遍历数组UndefinedforEachcallbackFn, thisArg

有回调函数参数的方法

有回调函数作为参数,意味着该方法非常灵活,应用范围更加宽广,特作此分类索引。

回调函数用于遍历

分类说明返回值函数名称函数参数
测试是否全部元素满足条件BooleaneverycallbackFn, thisArg
是否部分元素满足条件BooleansomecallbackFn, thisArg
筛选筛选数组元素ArrayfiltercallbackFn, thisArg
查找找到符合条件的第一个元素AnyfindcallbackFn, thisArg
找到符合条件的最后一个元素AnyfindLastcallbackFn, thisArg
找到符合条件的第一个元素的索引值NumberfindIndexcallbackFn, thisArg
找到符合条件的最后一个元素的索引值NumberfindLastIndexcallbackFn, thisArg
遍历遍历数组UndefinedforEachcallbackFn, thisArg
遍历并修改元素映射并展平数组ArrayflatMapcallbackFn, thisArg
映射数组ArraymapcallbackFn, thisArg
累积运算每个元素均参与累积运算AnyreducecallbackFn, initialValue

回调函数用于比较

分类说明返回值函数名称函数参数
排序原地排序ArraysortcompareFn
在新数组中排序ArraytoSortedcompareFn

参考资源

  1. ECMA 262: Array Objects