Reputation: 842
I'm trying to create a nested hash map in js like in the example below:
let rooms = {};
rooms[roomNum][personName] = somethings
the problem is that when I try to do that I recive this error:
TypeError: Cannot set property 'personName' of undefined
I'm able to create just a "one level hash map" like that rooms[roomNum] = somethings
Upvotes: 0
Views: 688
Reputation: 6757
rooms[roomNum]
is not defined so you can't add something to rooms[roomNum][personName]
Here is an example on how you can do what you want to do:
let rooms = {};
rooms[roomNum] = {};
rooms[roomNum][personName] = somethings;
Upvotes: 2