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 ArticleAnswer 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 ArticleAnswer 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 ArticleAnswer 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 ArticleHow 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