I have some data that I'm pushing to an array.
I want to have a loop and each time to push the data to a different array.
Let's say first array is player1, second array should be player2
etc. I only need 2 players now.
But i'm just curious how do I do this with as many players as I want.
I'm trying to make a chess game. Here's how my code looks so far:
function Figuri() {
this.player1 = [];
this.player2 = [];
figurkiNames.forEach(function(figura) {
});
for (var y = 1; y <= 2; y++) {
for (var i = 0; i < 8; i++) {
this.player1.push(new Figurka(i, figurkiNames[i], y, i+1, 8))
}
for (var i = 8; i < 16; i++) {
this.player1.push(new Figurka(i, "peshka", y, i-7, 7))
}
}
}
When y is 1 I need to push to array: "player1". When y is 2 I need to push to array: "player2" etc. And maybe I can have 100 players if i want to.
How do I do this in JavaScript?