Array<T>.prototype.*
-
concat(...items: (T | Array<T>)[]): T[]π ES3Returns a new array that is the concatenation of
thisand allitems. Non-array parameters are treated as if they were arrays with single elements.> ['a'].concat('b', ['c', 'd']) [ 'a', 'b', 'c', 'd' ] -
copyWithin(target: number, start: number, end=this.length): thisβοΈ ES6Copies the elements whose indices range from
startto (excl.)endto indices starting withtarget. Overlapping is handled correctly.> ['a', 'b', 'c', 'd'].copyWithin(0, 2, 4) [ 'c', 'd', 'c', 'd' ] -
entries(): Iterable<[number, T]>π ES6Returns an iterable over [index, element] pairs.
> Array.from(['a', 'b'].entries()) [ [ 0, 'a' ], [ 1, 'b' ] ] -
every(callback: (value: T, index: number, array: Array<T>) => boolean, thisArg?: any): booleanπ ES5Returns
trueifcallbackreturnstruefor every element. Stops as soon as it receivesfalse. Math: β> [1, 2, 3].every(x => x > 0) true > [1, -2, 3].every(x => x > 0) false -
fill(value: T, start=0, end=this.length): thisβοΈ ES6Assigns
valueto every index.> [0, 1, 2].fill('a') [ 'a', 'a', 'a' ] -
filter(callback: (value: T, index: number, array: Array<T>) => any, thisArg?: any): T[]π ES5Returns an array with only those elements for which
callbackreturnstrue.> [1, -2, 3].filter(x => x > 0) [ 1, 3 ] -
find(predicate: (value: T, index: number, obj: T[]) => boolean, thisArg?: any): T | undefinedπ ES6The result is the first element for which
predicatereturnstrue. If it never does, the result isundefined.> [1, -2, 3].find(x => x < 0) -2 > [1, 2, 3].find(x => x < 0) undefined -
findIndex(predicate: (value: T, index: number, obj: T[]) => boolean, thisArg?: any): numberπ ES6The result is the index of the first element for which
predicatereturnstrue. If it never does, the result is-1.> [1, -2, 3].findIndex(x => x < 0) 1 > [1, 2, 3].findIndex(x => x < 0) -1 -
forEach(callback: (value: T, index: number, array: Array<T>) => void, thisArg?: any): voidπ ES5Calls
callbackfor each element.['a', 'b'].forEach((x, i) => console.log(x, i)) // 'a' 0 // 'b' 1
-
includes(searchElement: T, fromIndex=0): booleanπ ES2016Returns
trueifsearchElementis an element andfalse, otherwise.> [0, 1, 2].includes(1) true > [0, 1, 2].includes(5) false -
indexOf(searchElement: T, fromIndex=0): numberπ ES5Returns the index of the first element that is strictly equal to
searchElement. Returns-1if there is no such element. Starts searching at indexfromIndex, visiting subsequent indices next.> ['a', 'b', 'a'].indexOf('a') 0 > ['a', 'b', 'a'].indexOf('a', 1) 2 > ['a', 'b', 'a'].indexOf('c') -1 -
join(separator = ','): stringπ ES1Creates a string by concatenating string representations of all elements, separating by
separator.> ['a', 'b', 'c'].join() 'a,b,c' > ['a', 'b', 'c'].join('##') 'a##b##c' -
keys(): Iterable<number>π ES6Returns an iterable over the keys of the array.
> [...['a', 'b'].keys()] [ 0, 1 ] -
lastIndexOf(searchElement: T, fromIndex=this.length-1): numberπ ES5Returns the index of the first element that is strictly equal to
searchElement. Returns-1if there is no such element. Starts searching at indexfromIndex, visiting preceding indices next.> ['a', 'b', 'a'].lastIndexOf('a') 2 > ['a', 'b', 'a'].lastIndexOf('a', 1) 0 > ['a', 'b', 'a'].lastIndexOf('c') -1 -
map<U>(callback: (value: T, index: number, array: ReadonlyArray<T>) => U, thisArg?: any): U[]π ES5Returns a new array, in which every element is the result of
callbackbeing applied to the corresponding element ofthis.> [1, 2, 3].map(x => x * 2) [ 2, 4, 6 ] > ['a', 'b', 'c'].map((x, i) => i) [ 0, 1, 2 ] -
pop(): T | undefinedβοΈ ES3Removes and returns the last element of the array. That is, it treats the end of the array as a stack.
> const arr = ['a', 'b', 'c']; > arr.pop() 'c' > arr [ 'a', 'b' ] -
push -
reduce -
reduceRight -
reverse -
shift -
slice -
some -
sort -
splice -
toLocaleString -
toString -
unshift -
values(): Iterable<T>
How holes are handled is described in Sect. βArray operations and holesβ in βExploring ES6β.