Answers for "javascript index in array"

1

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]
Posted by: Guest on September-30-2020
4

javasript array indexof

var array = [2, 9, 9];
array.indexOf(2);     // 0
array.indexOf(7);     // -1
array.indexOf(9, 2);  // 2
array.indexOf(2, -1); // -1
array.indexOf(2, -3); // 0
Posted by: Guest on June-12-2020

Code answers related to "javascript index in array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language