-1

I want to achieve this: enter image description here

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.

Lucas David Ferrero
  • 1,630
  • 14
  • 40

2 Answers2

2
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...

sifriday
  • 4,342
  • 1
  • 13
  • 24
  • https://stackoverflow.com/questions/695050/how-do-i-add-a-property-to-a-javascript-object-using-a-variable-as-the-name – sifriday Oct 03 '17 at 15:45
  • https://stackoverflow.com/questions/1184123/is-it-possible-to-add-dynamically-named-properties-to-javascript-object – sifriday Oct 03 '17 at 15:47