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:

There are many arr…


This content originally appeared on DEV Community and was authored by Iftakher Hossen

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.


This content originally appeared on DEV Community and was authored by Iftakher Hossen


Print Share Comment Cite Upload Translate Updates
APA

Iftakher Hossen | Sciencx (2021-12-21T18:00:04+00:00) JavaScript Array Related Methods. Retrieved from https://www.scien.cx/2021/12/21/javascript-array-related-methods/

MLA
" » JavaScript Array Related Methods." Iftakher Hossen | Sciencx - Tuesday December 21, 2021, https://www.scien.cx/2021/12/21/javascript-array-related-methods/
HARVARD
Iftakher Hossen | Sciencx Tuesday December 21, 2021 » JavaScript Array Related Methods., viewed ,<https://www.scien.cx/2021/12/21/javascript-array-related-methods/>
VANCOUVER
Iftakher Hossen | Sciencx - » JavaScript Array Related Methods. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/21/javascript-array-related-methods/
CHICAGO
" » JavaScript Array Related Methods." Iftakher Hossen | Sciencx - Accessed . https://www.scien.cx/2021/12/21/javascript-array-related-methods/
IEEE
" » JavaScript Array Related Methods." Iftakher Hossen | Sciencx [Online]. Available: https://www.scien.cx/2021/12/21/javascript-array-related-methods/. [Accessed: ]
rf:citation
» JavaScript Array Related Methods | Iftakher Hossen | Sciencx | https://www.scien.cx/2021/12/21/javascript-array-related-methods/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.