DEV Community

Discussion on: Handy JavaScript Array Tips

Collapse
 
aumayeung profile image
John Au-Yeung • Edited

You can use the filter method.

This means you write something like:

arr.filter(x => x % 2 === 0).reduce((a, b) => a + b, 0)

where arr is your array of numbers.