Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
December 21, 2021 06:00 pm GMT

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 its a subclass of Object.

Example of Array:

Array Code Example

There are many array methods in JavaScript. Lets know about them:

  • isArray(): isArray() method is used to know if the object is an array or not. When it returns true that means its an Array and when it returns false that means its 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 theres 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 theres 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 theres 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.


Original Link: https://dev.to/iftakher_hossen/javascript-array-related-methods-4ajn

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To