DEV Community

Discussion on: 1 line of code: How to get every n-th item of an Array

Collapse
 
jonrandy profile image
Jon Randy πŸŽ–οΈ • Edited

This method is hundreds of times faster...

const nthItems = (arr, pos) => Array.from({length:~~(arr.length/pos)}, (_,i)=>arr[(i+1)*pos-1])
Enter fullscreen mode Exit fullscreen mode
Collapse
 
martinkr profile image
Martin Krause

Amazing, thank you.

I updated the article and the code.

Cheers!