Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 140161

Retrieve an evenly distributed number of elements from an array

$
0
0

I know how to extract every nth item in an array, but what I have difficulties with is the following:

How can I extract every nth item from an array of 1800 elements, always including the first and the last element, up to a total of 256 elements?

Example:

array = [1,2,3,4,5,6,7,8,9,10];

Extract 5 elements:

extract = [1,3,5,7,10];

Viewing all articles
Browse latest Browse all 140161

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>