Home > Enterprise >  How to get my variable works as a variable and not a property of object?
How to get my variable works as a variable and not a property of object?

Time:12-13

here is the deal

   if(!userExist) {
          userJson["user"] = [{"name": msg.author.username, "commands": { userCommand : userCommandValue }}]
    }

edit: to avoid confusion, this is my userCommand :

let userCommand = msg.content;

userCommand is considered like a property and not like a variable existing...

Is there a way to bypass that ?

CodePudding user response:

As of ES6, your can do this: wrap a [] arount userCommand

if(!userExist) {
      userJson["user"] = [{"name": msg.author.username, "commands": { [userCommand] : userCommandValue }}]
}

  • Related