Arrays Methods

Contact Us or call 1-877-932-8228
Arrays Methods

Arrays Methods

We'll look into the methods listed in the table below. Note that Array.method() implies that the method is static (i.e. belongs to the class Array) and is applied like Array.method(argument). Those methods with signature Array.prototype.method() means the method should be applied to an instances, like arr.method().

Array Methods
Method Description
Array.from(collection, mapFunction?, thisArgument?) Creates a new Array instance from a array-like collection, like the arguments of a function, a Set, a Map, a String, etc. Optionally apply a function mapFunction on every element and optionally apply a value (thisArgument) to use as this when executing mapFunction.
Array.isArray(object) Returns true if object is an array, false if not.
Array.of(element0?, element1?, ...) Creates a new Array instance from its arguments (any number of arguments). Differs from the default Array contructor in that Array.of(3) creates a new instance with single element 3, where new Array(3) creates a new instance with three elements all with value undefined.
Array.prototype.fill(value, start?, end?) Fills all elements of an array with a static value from start to end, inclusive of start and exclusive of end. start defaults to 0 and end defaults to the array's length.
Array.prototype.filter(callbackFunction, thisArgument?) Creates new array with all elements for which the application of the callbackFunction returns true, with optional thisArgument value to use as this when executing the callbackFunction.
Array.prototype.find(callbackFunction, thisArgument?) Returns the first value from the array for which callbackFunction returns true, with optional thisArgument value to use as this when executing the callbackFunction. Returns undefined is no element is found.
Array.prototype.forEach(callbackFunction, thisArgument?) Executes callbackFunction once per each array element, with optional thisArgument value to use as this when executing callbackFunction.
Array.prototype.indexOf(elementToFind, start?) Returns the first index at which elementToFind can be found, or -1 if elementToFind is not present. The optional start parameter (defaulting to 0) is the index from which to start searching.
Array.prototype.keys() Returns a new Array Iterator containing the keys from the array.
Array.prototype.map(callbackFunction, thisArgument?) Creates new array from the application of callbackFunction on each element of the original array, with optional thisArgument value to use as this when executing callbackFunction.
Array.prototype.reduce(callbackFunction, initialValue?) Returns a single value from the application of callbackFunction to each element of the array against an accumulated value, with optional initialValue parameter to use at the starting accumulated value. Useful, for example, to find the sum of the elements of an array.
Next