Quantcast
Channel: How to select numbers in array - Stack Overflow
Browsing latest articles
Browse All 5 View Live

Answer by Penguin for How to select numbers in array

//this function splits arrays into groups of nfunction chunk(arr, limit) { var chunks = []; for (var i=0,len=arr.length; i<len; i+=limit) chunks.push(arr.slice(i,i+limit)); return chunks;}var arr =...

View Article


Answer by Omar Matijas for How to select numbers in array

var arr = [4, 5, 3, 2, 3, 1, 4, 5, 3], filtered = arr.filter((val,idx) => idx % 3 == 1);

View Article


Answer by Mosè Raguzzini for How to select numbers in array

You have to split the array in chunks, then take the second element of every chunk:/** * Returns an array with arrays of the given size. * * @param myArray {Array} array to split * @param chunk_size...

View Article

Answer by antonku for How to select numbers in array

You can use Array.prototype.filter and modulo operation:const result = [4, 5, 3, 2, 3, 1, 4, 5, 3].filter((item, i) => (i+2) % 3 === 0);console.log(result)

View Article

How to select numbers in array

I'm trying to select every second element in the group of three. e.g.[4, 5, 3, 2, 3, 1, 4, 5, 3]Result: 5, 3, 5How can I achieve this?

View Article

Browsing latest articles
Browse All 5 View Live


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