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βοΈ ES6- Assigns
valueto every index. [0, 1, 2].fill('a') β [ 'a', 'a', 'a' ]
- Assigns
-
filter(callback: (value: T, index: number, array: Array<T>) => any, thisArg?: any): T[]π ES5- Returns an array with only those elements for which
callbackreturnstrue. [1, -2, 3].filter(x => x > 0) β [ 1, 3 ]
- Returns an array with only those elements for which
-
find(predicate: (value: T, index: number, obj: T[]) => boolean, thisArg?: any): T | undefinedπ ES6- The 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
- The result is the first element for which
-
findIndex(predicate: (value: T, index: number, obj: T[]) => boolean, thisArg?: any): numberπ ES6- The 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
- The result is the index of the first element for which
-
forEach(callback: (value: T, index: number, array: Array<T>) => void, thisArg?: any): voidπ ES5- Calls
callbackfor each element. ['a', 'b'].forEach((x, i) => console.log(x, i))
- Calls
-
includes(searchElement: T, fromIndex=0): booleanπ ES2016- Returns
trueifsearchElementis an element andfalse, otherwise. [0, 1, 2].includes(1) β true[0, 1, 2].includes(5) β false
- Returns
-
indexOf(searchElement: T, fromIndex=0): numberπ ES5- Returns 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
- Returns the index of the first element that is strictly equal to
-
join(separator = ','): stringπ ES1- Creates 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'
- Creates a string by concatenating string representations of all elements, separating by
-
keys(): Iterable<number>π ES6- Returns an iterable over the keys of the array.
[...['a', 'b'].keys()] β [ 0, 1 ]
-
lastIndexOf(searchElement: T, fromIndex=this.length-1): numberπ ES5- Returns 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
- Returns the index of the first element that is strictly equal to
-
map<U>(callback: (value: T, index: number, array: ReadonlyArray<T>) => U, thisArg?: any): U[]π ES5- Returns 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 ]
- Returns a new array, in which every element is the result of
-
pop(): T | undefinedβοΈ ES3Treats the end of the array as a stack and removes the last element.
> const arr = ['a', 'b', 'c']; undefined > 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β.