I've tried this:
userId: {
isAdmin: false,
}
userId is a const where its value is like 447785 but the resulted object just show userId as a property not a value.
I've tried this:
userId: {
isAdmin: false,
}
userId is a const where its value is like 447785 but the resulted object just show userId as a property not a value.
var users = {}
users[userId] = {isAdmin: false}
Feels like this is probably a dupe of a Q on SO that explains it properly. I'll have a look...
Use this
{
[userId]: {
isAdmin: false
}
}
More here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#New_notations_in_ECMAScript_2015 and here http://www.benmvp.com/learning-es6-enhanced-object-literals/#computed-property-keys