How would I add a "property" to an object? I tried: players[data.id].name = data.name;
but it's not working.
Edit: this worked, thanks for the help guys!:
players[data.id] = {name: "Johnny"};
What I want to achieve: (data.id is already defined)
var players = {};
players[data.id].name = "Johnny";
players[data.id].age = 13;
console.log(players[data.id].name]); ---> Johnny
playersobject associates a key to aPlayerobject, you can easily do itplayers[data.id]before adding properties to it, like:var players = {}; players[data.id] = {}; players[data.id].name = "Johnny"; players[data.id].age = 13;. Or maybe you can write:var players = {}; players[data.id] = {name: "Johnny", age: 13};