Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
December 22, 2021 04:24 pm GMT

Important array methods

1. concat()
Joins two or more arrays, and returns a copy of the joined arrays

Image description
the fullName will show Pritom Deb

2. every((element, index, array) => { /* ... */ })
Checks if every element in an array pass a test

Image description
teenager will reply true while adult while reply false. The every() method only returns true or false. The every() method does not execute the function for empty elements. The every() method does not change the original array

3. filter((element, index, array) => { /* ... */ })
Creates a new array with every element in an array that pass a test

Image description
adult will return a new array ["18","19","20"]

4. find((element, index, array) => { /* ... */ })
Returns the value of the first element in an array that pass a test

Image description
adult will return 18.

5. findIndex((element, index, array) => { /* ... */ })
Returns the index of the first element in an array that pass a test

Image description
adult will return 3.

6. forEach((element, index, array) => { /* ... */ })
Calls a function for each array element

Image description
adult will return undefined. It is very important to note that forEach only iterate through a array. It doesn't return any value.

7. Array.form(arrayLike, (element, index) => { /* ... */ })
Creates an array from an object

Image description
nameArray will return ["p", "r", "i", "t", "o", "m"]

8. includes(searchElement)
Calls a function for each array element

Image description
adult will return undefined. It is very important to note that forEach only iterate through a array. It doesn't return any value.


Original Link: https://dev.to/pritomdbhaskar/important-array-methods-2dja

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