Search code snippets, questions, articles...

Filter array

const list = [1,2,3,4,5]

const even_list = list.filter((accumulator,element)=>{
    return element % 2 == 0
})
Output
[2,4]

filter() and reduce() will iterate over all the array items, while find() will be faster.

Was this helpful?
0 Comments
Programming Feeds
Learn something new everyday on Devsheet