0

I want to create something like php associative array in JavaScript. I know there are objects

var obj = 
{
    property1: "value1" ,
    ...
};

In this case I have to call obj.property1 But while script is running I get string "property1", so I would like to call it like obj."property1", but I don't know what exactly should write.

  • 1
    Does this answer your question? [Dynamically access object property using variable](https://stackoverflow.com/questions/4244896/dynamically-access-object-property-using-variable) – evolutionxbox Jul 25 '21 at 15:07
  • Use `obj['property1']` – Naren Jul 25 '21 at 15:07
  • 1
    A couple of side notes on terminology (in order to be helpful, not snarky): It's a "property," not a "variable." You don't "call" variables (or properties), you "use" them or "reference" them or "get" values from them or "assign" values to them, etc. You "call" functions and methods and constructors (that is, things that **do** things). – T.J. Crowder Jul 25 '21 at 15:10

0 Answers0