Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript hash map with 2 values

Tags:

javascript

Is There a way to do an hash map in javascript that holds 1 key and 2 values?

For an hash map with key and value in javascript i can do something like this:

var userList = {
     11234321:"koko",
     22342342:"jojo",
     32342423:"fofo",
     42342342:"momo"                    
    }

So for each ID number i have user name.

Now, i want to add another value, like: user age.

There is a way to do that? any other solution to the problem?

like image 428
lolo Avatar asked Jun 10 '26 06:06

lolo


1 Answers

I'd recommend having the value as another hash

var userList = {
    11234321: {
        username: 'koko',
        age: 44
    }
}
like image 66
Sindri Guðmundsson Avatar answered Jun 11 '26 19:06

Sindri Guðmundsson