DEV Community

Iftakher Hossen
Iftakher Hossen

Posted on • Updated on

JavaScript Array Related Methods

In JavaScript, Array is a variable that stores multiple elements. We used Array to store the list of elements and access with a single name. An array is a reference type, which defines it’s a subclass of Object.

Example of Array:

Array Code Example

There are many array methods in JavaScript. Let’s know about them:

  • isArray(): isArray() method is used to know if the object is an array or not. When it returns true that means it’s an Array and when it returns false that means it’s not an Array.

  • concat(): concat() method is used to concat/join two or more arrays together. After using this method it returns the new array. It never changes the existing arrays.

  • every(): every() method is used to execute a specific function for every element of an array. If the function returns true it clarifies all the elements are true and if the function returns false it clarifies all the elements are false.

  • filter(): filter() method is used to filter out some elements in a specific condition. It creates a new array with the results. It returns all the elements that fulfill the condition.

  • find(): find() method is used to find an element in a specific condition. It returns the first element that fulfills the condition.

  • findIndex(): findIndex() method is used to find out the index of an element that fulfills the condition. If there’s no match it returns -1.

  • forEach(): forEach() method is used to execute a function for each array element.

  • indexOf(): indexOf()is used to get the index of a specific value. If there’s no match it returns -1.

  • join(): join() method is used to return the array as a string.

  • map(): map() method is used to execute a function for each array element.

  • lastIndexOf(): lastIndexOf() is used to get the last index of a specific value. If there’s no match it returns -1.

  • pop(): pop() method is used to delete the last element of an array.

  • push(): push() method is used to add an element to the end of an array.

  • Reduce(): Reduce() method is used to execute a reducer function for an array element to calculate the numbers of an array.

  • Reverse(): Reverse() method is used to reverse the order of the items of an array.

  • shift(): shift() method is used to delete the first element of an array.

  • slice(): slice() method is used to get specific elements in a new array.

  • sort(): sort() method is used to sort the elements of an array in alphabetical and ascending order.

  • splice(): splice() method is used to delete a specific element of an array.

  • unshift(): unshift() method is used to add an element to the beginning of an array.

Thank you for reading this!

Top comments (2)

Collapse
 
kasfiyaupoma profile image
KasfiyaUpoma

Thats great! Thanks for sharing💖

Collapse
 
iftakher_hossen profile image
Iftakher Hossen

Thanks for appricieating.