DEV Community

Praveen
Praveen

Posted on

Javascript iteration method

For each method
The forEach() method calls a function for each element in an array.
Const marks =[24,35,100,47,55,65]
Marks.forEach(display);
Function display (V);{
Console.log(V);
}
We can able to get value,index,array

For.map method
map() creates a new array from calling a function for every array element.

map() does not execute the function for empty elements.

map() does not change the original array.
Const marks =[100,99,98,96,75];
Marks.map=(display)
Function display (V)
{
Return v+3
}
flat map

The flatMap() method first maps all elements of an array and then creates a new array by flattening the array.
Const products =["car,bike","sofa,bed","shirt,pant"
Console.log (products.map(a=>a.split(","));
Filter
const numbers = [45, 4, 9, 16, 25];
const over18 = numbers.filter(myFunction);

function myFunction(value, index, array) {
return value > 18;
}

Top comments (0)