DEV Community

baltz
baltz

Posted on

2 2

Quick tip! Map loop, already returns a array

It is common to see this approach when we are creating a new array using map loop

const newArray = []

array.map((item) => {
  newArray.push(item.value)
})
Enter fullscreen mode Exit fullscreen mode

Right? but map loop already returns a array.
So we can do that instead

const newArray = array.map((item) => {
  return item.value
})

Enter fullscreen mode Exit fullscreen mode

Cool huh!

Cool huh!

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More