How can I adjust this code so that when I press each button, the console.log displays a different slice of the array instead of always showing me the last 20 elements?
for (var i = 0; i < array.length; i++) {
var b;
var NewArr = [];
if (i % 20 == 0) {
NewArr = array.slice(i, i + 20);
b = createButton(i + "-" + (i + 20), NewArr);
b.position(x, y + i * 1.5);
b.mousePressed(function () {
console.log(NewArr);
});
}
}