An Interest In:
Web News this Week
- April 23, 2024
- April 22, 2024
- April 21, 2024
- April 20, 2024
- April 19, 2024
- April 18, 2024
- April 17, 2024
Important array methods
1. concat()
Joins two or more arrays, and returns a copy of the joined arrays
the fullName will show Pritom Deb
2. every((element, index, array) => { /* ... */ })
Checks if every element in an array pass a test
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
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
5. findIndex((element, index, array) => { /* ... */ })
Returns the index of the first element in an array that pass a test
6. forEach((element, index, array) => { /* ... */ })
Calls a function for each array element
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
nameArray will return ["p", "r", "i", "t", "o", "m"]
8. includes(searchElement)
Calls a function for each array element
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
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To