JavaScript array method every developer should know!

Arrays are one of the most popular and useful object in JavaScript. There are lots of build in properties and method associated with arrays. I have listed top array methods every developer should know and make their life easier when dealing with arrays.

  • push()
  • pop()
  • shift()
  • unshift()
  • concat()
  • slice()
  • splice()
  • reverse()
  • every()
  • join()
  • forEach()
  • map()
  • filter()
  • find()
  • reduce()
  • sort()

push()

push append element to the end of an array.

pop()
pop extract the last element of an array and return that element.

shift()
shift extract the first element of an array and return that element.

unshift()
unshift append an element to the beginning of an array.

concat()
The concat method is used to create new array by merging two or more arrays.

slice()
The slice method is used to create new array using selected element from an array without changing the contents of that array.

splice()
The splice method is used to delete, replace or insert a new element to an array. It changes the contents of existing array.

reverse()
The reverse method reverse element of an array.

join()
The join method is used to concat all the elements of an array separated by commas or any specific separator string.

every()
The every method tests whether all element of an array pass the test implemented by a callback function and return Boolean value.

forEach()
The forEach accepts a callback function and executes the callback function once for each of the element of an array.

map()
The map accepts a callback function and executes the callback function and return a new array.

filter()
The filter accepts a callback function and creates a new array with all elements that pass the test implemented by that function.

find()
The find accepts a callback function and returns the value of the first element which pass the test implemented by that function.

reduce()
The reduce method applies a callback function simultaneously against two values from left to right of an array and reduce it to a single value.

sort()
The sort method allows to sort elements of an array in place. The default sorting order is ascending