-1

How would you run a function, once for each object in an array, using the object as an arguement in a function?

1 Answers1

0

There ways of iteration on an array but map is an efficient one you can simple do this as .map() accepts a callback function as one of its arguments, and an important parameter of that function is the current value of the item being processed by the function. This is a required parameter. With this parameter, you can modify each item in an array and return it as a modified member of your new array.

const sweetArray = [2, 3, 4, 5, 35]
const sweeterArray = sweetArray.map(sweetItem => {
    return sweetItem * 2
})

console.log(sweeterArray)

Output

[ 4, 6, 8, 10, 70 ]