1

How can I get the value of another object from the same JSON while declaring?

var constant = {

    roles: {
      ADMIN: 'admin',
      CONSUMER: 'consumer',
      SUPER_ADMIN: "super_admin"
    },

    webAccess : [roles.ADMIN]

}

console.log(constant);

Expected output:

{
  "roles": {
    "ADMIN": "admin",
    "CONSUMER": "consumer",
    "SUPER_ADMIN": "super_admin"
  },
  "webAccess": [
    "admin"
  ]
}
Ash
  • 672
  • 6
  • 21
Hardik Shah
  • 4,042
  • 2
  • 20
  • 41

1 Answers1

0

You can do this as following:

var constant = {

    roles: {
      ADMIN: 'admin',
      CONSUMER: 'consumer',
      SUPER_ADMIN: "super_admin"
    },

    get webAccess() {
        return [this.roles.ADMIN];
    } 

}

console.log(constant);
Pramod Kumar
  • 96
  • 1
  • 2
  • 7