const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const newArr = arr.map((element, index) => {if ((index + 1) % 3 === 0) {return 0;} else {return element;}});
console.log(newArr); // [1, 2, 0, 4, 5, 0, 7, 8, 0, 10]
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const newArr = arr.map((element, index) => {
if ((index + 1) % 3 === 0) {
return 0;
} else {
return element;
}
});
console.log(newArr); // [1, 2, 0, 4, 5, 0, 7, 8, 0, 10]