# `Array` `Array.prototype.*` * `concat(...items: (T | Array)[]): T[]` πŸ”’ ES3 Returns a new array that is the concatenation of `this` and all `items`. Non-array parameters are treated as if they were arrays with single elements. ```repl > ['a'].concat('b', ['c', 'd']) [ 'a', 'b', 'c', 'd' ] ``` * `copyWithin(target: number, start: number, end=this.length): this` ✏️ ES6 Copies the elements whose indices range from `start` to (excl.) `end` to indices starting with `target`. Overlapping is handled correctly. ```repl > ['a', 'b', 'c', 'd'].copyWithin(0, 2, 4) [ 'c', 'd', 'c', 'd' ] ``` * `entries(): Iterable<[number, T]>` πŸ”’ ES6 Returns an iterable over [index, element] pairs. ```repl > Array.from(['a', 'b'].entries()) [ [ 0, 'a' ], [ 1, 'b' ] ] ``` * `every(callback: (value: T, index: number, array: Array) => boolean, thisArg?: any): boolean` πŸ”’ ES5 Returns `true` if `callback` returns `true` for every element. Stops as soon as it receives `false`. Math: βˆ€ ```repl > [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 `value` to every index. * `[0, 1, 2].fill('a') β†’ [ 'a', 'a', 'a' ]` * `filter(callback: (value: T, index: number, array: Array) => any, thisArg?: any): T[]` πŸ”’ ES5 * Returns an array with only those elements for which `callback` returns `true`. * `[1, -2, 3].filter(x => x > 0) β†’ [ 1, 3 ]` * `find(predicate: (value: T, index: number, obj: T[]) => boolean, thisArg?: any): T | undefined` πŸ”’ ES6 * The result is the first element for which `predicate` returns `true`. If it never does, the result is `undefined`. * `[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` πŸ”’ ES6 * The result is the index of the first element for which `predicate` returns `true`. 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) => void, thisArg?: any): void` πŸ”’ ES5 * Calls `callback` for each element. * `['a', 'b'].forEach((x, i) => console.log(x, i))` * `includes(searchElement: T, fromIndex=0): boolean` πŸ”’ ES2016 * Returns `true` if `searchElement` is an element and `false`, otherwise. * `[0, 1, 2].includes(1) β†’ true` * `[0, 1, 2].includes(5) β†’ false` * `indexOf(searchElement: T, fromIndex=0): number` πŸ”’ ES5 * Returns the index of the first element that is strictly equal to `searchElement`. Returns `-1` if there is no such element. Starts searching at index `fromIndex`, 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` πŸ”’ 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'` * `keys(): Iterable` πŸ”’ 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 `-1` if there is no such element. Starts searching at index `fromIndex`, visiting preceding indices next. * `['a', 'b', 'a'].lastIndexOf('a') β†’ 2` * `['a', 'b', 'a'].lastIndexOf('a', 1) β†’ 0` * `['a', 'b', 'a'].lastIndexOf('c') β†’ -1` * `map(callback: (value: T, index: number, array: ReadonlyArray) => U, thisArg?: any): U[]` πŸ”’ ES5 * Returns a new array, in which every element is the result of `callback` being applied to the corresponding element of `this`. * `[1, 2, 3].map(x => x * 2) β†’ [ 2, 4, 6 ]` * `['a', 'b', 'c'].map((x, i) => i) β†’ [ 0, 1, 2 ]` * `pop(): T | undefined` ✏️ ES3 Treats the end of the array as a stack and removes the last element. ```repl > 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` How holes are handled is described in Sect. β€œ[Array operations and holes](http://exploringjs.com/es6/ch_arrays.html#_array-operations-and-holes)” in β€œExploring ES6”.