I've been stuck for a couple hours now trying to randomly select one item from one array (players) to another (team1).
I've got it working by doing something else with splice, but unfortunately splice creates an array itself with the removed items and so I ended up getting an array with an array.
This is what I got so far:
var players = ["P1", "P2", "P3", "P4"];
var team1 = [];
var team2 = [];
var select = Math.floor(Math.random() * players.length);
var tmp;
if (team1.length < 2) {
tmp.push(players.splice(select, 1));
team1.push(tmp.pop);
}
console.log(team1);
console.log(tmp);
console.log(players);
If I'm doing this all wrong I'm sorry, still pretty new to this website, help is appreciated.
You just have to select the first element from the array while splicing and pushing to team,