JavaScript Array Methods

Deepak Sharma
5 min readMar 1, 2020

In this blog, we will learn about JavaScript Arrays Methods

Array.from()

The Array.from() method creates a new, shallow-copied Array instance from an array-like or iterable object.

Array.isArray()

The Array.isArray() method determines whether the passed value is an Array.

Array.of()

The Array.of() method creates a new Array instance from a variable number of arguments, regardless of number or type of the arguments.

Array.concat()

The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.

Array.copyWithin()

The copyWithin() method copies part of an array to the same array and returns it, without modifying its size i.e, copies array element of a array within the same array.

Array.entries()

The entries() method returns a new Array Iterator object that contains the key/value pairs for each index in the array.

Array.every()

The every() method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.

Array.fill()

Array.fill() method is used to fill the array with a given static value. The value can be used to fill the entire array or it can be used to fill a part of the array.

Array.filter()

arr.filter() method is used to create a new array from a given array consisting of only those elements from the given array which satisfy a condition set by the argument function.

Array.find()

The find() method returns the value of the first element in the provided array that satisfies the provided testing function.

Array.findIndex()

The findIndex() method returns the index of the first element in the array that satisfies the provided testing function. Otherwise, it returns -1, indicating that no element passed the test.

Array.flat()

The flat() method creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.

Array.flatMap()

The flatMap() method first maps each element using a mapping function, then flattens the result into a new array. It is identical to a map() followed by a flat() of depth 1, but flatMap() is often quite useful, as merging both into one method is slightly more efficient.

Array.forEach()

The forEach() method executes a provided function once for each array element.

Array.includes()

The includes() method determines whether an array includes a certain value among its entries, returning true or false as appropriate.

Array.indexOf()

The indexOf() method search the array for an element and returns its position

Array.join()

The join() method joins all elements of an array into a string

Array.keys()

The keys() method returns a new Array Iterator object that contains the keys for each index in the array.

Array.lastIndexOf()

The lastIndexOf() method search the array for an element, starting at the end, and returns its position

Array.map()

The map() method creates a new array with the result of calling a function for each array element

Array.pop()

The pop() method removes the last element from an array and returns that element. This method changes the length of the array.

Array.push()

The push() method adds one or more elements to the end of an array and returns the new length of the array.

Array.reduce()

The reduce() method executes a reducer function (that you provide) on each element of the array, resulting in a single output value.

Array.reduceRight()

The reduceRight() method reduce the values of an array to a single value (going right-to-left)

Array.reverse()

The reverse() method reverses the order of the elements in an array

Array.shift()

The shift() method removes the first element of an array, and returns that element

Array.slice()

The slice() method selects a part of an array, and returns the new array

Array.some()

The some() method checks if any of the elements in an array pass a test

Array.sort()

The sort() method sorts the elements of an array and returns the sorted array. The default sort order is ascending.

Array.splice()

The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.

Array.toLocaleString()

The toLocaleString()method returns a string representing the elements of the array. The elements are converted to Strings using their toLocaleString methods and these Strings are separated by a locale-specific String (such as a comma “,”).

Array.toString()

The toString()method converts an array to a string, and returns the result

Array.unshift()

The unshift()method adds new elements to the beginning of an array, and returns the new length

Array.values()

The values()method returns a new Array Iterator object that contains the values for each index in the array.

--

--