Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js array return only certain positions

const every_nth = (arr, nth) => arr.filter((e, i) => i % nth === nth - 1);
console.log(every_nth([1, 2, 3, 4, 5, 6], 1));
console.log(every_nth([1, 2, 3, 4, 5, 6], 2));
console.log(every_nth([1, 2, 3, 4, 5, 6], 3));
console.log(every_nth([1, 2, 3, 4, 5, 6], 4));

// OUTPUT

[1,2,3,4,5,6]
[2,4,6]
[3,6]
[4]
Comment

PREVIOUS NEXT
Code Example
Javascript :: How to empty a folder in Node.js 
Javascript :: return elemnt from array 
Javascript :: moment().toDate(); 
Javascript :: how to add js in flask 
Javascript :: generate a random id 
Javascript :: how to trigger on input event in javascript 
Javascript :: Object.hasOwnProperty.call 
Javascript :: append a query string to the url react 
Javascript :: promise states javascript 
Javascript :: convert number to word j 
Javascript :: express response setTimeout 
Javascript :: currying javascript sum 
Javascript :: classname did not match server next js styled components 
Javascript :: javascript folder dynamic import 
Javascript :: how to remove spaces from strings javascript 
Javascript :: how to push string into array in javascript 
Javascript :: java gson string to json 
Javascript :: unsubscribe all youtube channel using javascript 
Javascript :: remove double quotes from json array javascript 
Javascript :: javascript check image src 
Javascript :: change node version 
Javascript :: jspdf pdf from html 
Javascript :: pyspark from_json example 
Javascript :: add new element useState array 
Javascript :: get value of radio button javascript 
Javascript :: javascript if shorthand 
Javascript :: get client id socket io 
Javascript :: django pass list to javascript 
Javascript :: jquery get by name 
Javascript :: check if two rectangles overlap javascript canvas 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =