JavaScript cheat-sheet : array methods

Kevin Comba Gatimu
5 min readMay 20, 2022

--

1.concat()

The concat() method is used to join two or more arrays. This method does not change the existing arrays, but returns a new array, containing the values of the joined arrays.

2.copyWithin()

copies array elements to another position in the array, overwriting the existing values. This method will never add more items to the array. Note: this method overwrites the original array.

3.entries()

The entries() method returns an Array Iterator object with key/value pairs..

4.every()

The every() method checks if all elements in an array pass a test (provided as a function).

5.fill()

The fill() method fills the specified elements in an array with a static value. You can specify the position of where to start and end the filling. If not specified, all elements will be filled.

6.filter()

The filter() method creates an array filled with all array elements that pass a test (provided as a function).

7.find()

The find() method returns the value of the first element in an array that pass a test (provided as a function)

8.findIndex()

The findIndex() method returns the index of the first element in an array that pass a test (provided as a function)

9.forEach()

The forEach() method calls a function once for each element in an array, in order

10.includes()

The includes() method determines whether an array contains a specified element..

11.indexOf()

The indexOf() method searches the array for the specified item, and returns its position.

12.isArray()

The isArray() method determines whether an object is an array.Thinction returns true if the object is an array, and false if not

13.join()

Convert the elements of an array into a string. The join() method returns the array as a string.

14.lastIndexOf()

The lastIndexOf() method searches the array for the specified item, and returns its position.

15.map()

The map() method creates a new array with the results of calling a function for every array element.

16.pop()

The pop() method removes the last element of an array, and returns that element.

17.push()

The push() method adds new items to the end of an array, and returns the new length

18.reduce()

The reduce() method executes a provided function for each value of the array (from left-to-right) and reduces the array to a single value.

19.reduceRight()

The reduceRight() method executes a provided function for each value of the array (from right-toleft) and reduces the array to a single value

20.reverse()

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

21.some()

The some() method checks if any of the elements in an array pass a test (provided as a function). It executes the function once for each element present in the array

22.slice()

The slice() method selects the elements starting at the given start argument, and ends at, but does not include, the given end argument. It returns the selected elements in an array, as a new array object.

23.shift()

The shift() method removes the first item of an array.

24.sort()

The sort() method sorts the items of an array.

25.splice()

The splice() method adds/removes items to/from an array, and returns the removed item(s)

26.toString()

The toString() method returns a string with all the array values, separated by commas.

27.unshift()

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

28.valueOf()

The valueOf() method returns the array. This method is the default method of the array object. Array.valueOf() will return the same as Array

--

--

Kevin Comba Gatimu

🎇computer science student🎇Microsoft Learn Student Ambassador🎇 MERN stack🎇. Currently learning C#. LinkedIn https://www.linkedin.com/in/kevin-comba-gatimu