DEV Community

Discussion on: 1 line of code: How to get every even item of an Array

Collapse
 
lexlohr profile image
Alex Lohr

Or you use the fastest possible version:

const evenItems = (arr, out = [], i) => { for (i = 0; i < arr.length; i = i + 2) out.push(arr[i]); return out; };
Enter fullscreen mode Exit fullscreen mode
Collapse
 
martinkr profile image
Martin Krause

Hey!

thank you for taking the time to contribute, I put both functions to the performance benchmark on hasty and I'm going to update the article with your suggestion!

Cheers!