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
  • 704,970
  • 168
  • 1,303
  • 1,425
shanky singh
  • 1,021
  • 2
  • 12
  • 22

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
  • 44,345
  • 11
  • 88
  • 115