-2

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

1
  • I think so, thank you Commented May 31, 2022 at 16:13

1 Answer 1

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 ]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.