1

I have an object which is dynamic and its property values will change for different data.

eg : MyObj = { country :"Ind", Place : "Pune"}

Now I have one data value by which I can get first property which value I need to retrieve.

var MyArr = this.FiltArr[0].property;

This will return myArr = country and then later I will use like

MyObj.Myar = // my code..

This object and MyArr value is dyanmic. Obj may change and property of country may change to something else. Any idea how to achieve this?

Whenever I use MyArr I will get MyObj attribute which i need to play around. How to achieve this?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
shanky singh
  • 1,121
  • 2
  • 12
  • 24

1 Answers1

3

You have to use bracket notation for this:

var MyArr = this.FiltArr[0].property;
MyObj[MyArr] = // my code..

Bracket notation can use variables, so it is useful in your situation where the property names are dynamically determined (when the exact names are not known until runtime).

Mihai Alexandru-Ionut
  • 47,092
  • 13
  • 101
  • 128