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]
Also in JavaScript:
- how to add redirec router in angular
- Bots server count discord js
- express get full url
- upload image and video cloudinary expressjs
- javascript get date without time
- add authorization header axios
- discord.js message on member add
- pROGRAMMIZ
- js queryselector radio checked
- capacitor.ionicframework.com to apk
- How to check if a member has a role discord.js
- npl live server doesn't load js
- nuxt js lazy load page pagination
- how to download and install ssms in windows 10
- js add style to each class
- material ui align icon with text
- change text of paragraph jquery
- download a file nodejs
- optional chaining in javascript
- javascript jquery get form field value
- export { default as add } from './add.js'; ^^^^^^ SyntaxError: Unexpected token 'export'
- jquery append after
- state management in react
- generate thumbnail of pdf using pf js