When a user inputs the name of the players, I want my code to separate each player into a different object in my array. My code detects when commas "," are part of the text, but how can I use those commas "," to separate each player name into an individual object in my array.
var subject = [];
function addSubjects() {
namesInputted = document.getElementById('namesInputter').value;
if (namesInputted.includes(',') == true){
//HERE IS THE CODE I AM MISSING!!!
}else{
subject.push(namesInputted);
document.getElementById('namesInputter').value = null;
console.log(subject);
}
}
<div class="col-sm-5">
<h1>RETOS LOCOS</h1>
<input autocomplete="off" class="form-control" type="text" id="namesInputter" placeholder="Player Name" value="">
<button type="button" class="btn btn-primary" id="addSubjectsButton" onclick="addSubjects()">Add Player</button>
<button type="button" class="btn btn-primary" id="startGameButton" onclick="startGame()">Start Game</button>
</div>