For arrays, provide a way to get more, than one argument in on iteration.
let array = [1, 2, 3, 4];
// values only
foreach(
array,
2, // step by two
(a, b) => {
// 1, 2, then next will be 3, 4
console.log(a, b);
}
);
// values with indices
foreach(
array,
2, // step by two
(ai, av, bi, bv) => {
// '0 : 1, 1 : 2', then next will be '2 : 3, 3 : 4'
console.log(`${ai} : ${av}, ${bi} : ${bv}`);
}
);