0

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

1 Answer 1

2
  1. That's not a hashmap, it's an object
  2. 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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.