Advertisement
Google Ad Slot: content-top
JS Array Helper Method
ES6 introduced powerful array iteration methods that make working with arrays simpler, cleaner, and more readable. These helper methods iterate over arrays and apply functions to their elements.
forEach:
Executes a provided function once for each array element. It does not return anything.
map:
Creates a new array by applying a function to each element of the original array. It returns the transformed array.
find:
Returns the first element in the array that satisfies a specified condition. If no element matches, it returns undefined.
findIndex:
Returns the index of the first element that satisfies a specified condition. If no element matches, it returns -1.
filter:
Creates a new array containing elements that pass a specified condition (filter function). It returns the filtered array.
reduce:
Executes a reducer function on each element of the array, resulting in a single output value.
some:
Checks if at least one element in the array satisfies a specified condition. Returns true or false.
every:
Checks if all elements in the array satisfy a specified condition. Returns true or false.