5 Replies Latest reply on May 7, 2010 6:11 AM by Chris Callaghan

    How do I convert a string, and use a string as a property?

    Chris Callaghan

      I have an array in the following format:

       

      {ownsCar: 'true', ownsBike: 'true', ownsHouse: 'true'}

      {ownsCar: 'false', ownsBike: 'true', ownsHouse: 'true'}

      {ownsCar: 'true', ownsBike: 'false', ownsHouse: 'true'}

      etc ............

       

       

       

       

      And I need to test against each item e.g.

       

      if...

      myDataGrid[myItem].ownsCar == Object(myCheckbox).label

      ... then

       

      if...

      myDataGrid[myItem].ownsBike == Object(myCheckbox).label

      ... then

       

      if...

      myDataGrid[myItem].ownsHouse == Object(myCheckbox).label

      ... then

       

       

       

       

      But I need to build my application where the property (e.g. "ownsCar", "ownsBike", "ownsHouse") is a variable such as:

       

       

      if...

      myDataGrid[myItem].myProperty == Object(myCheckbox).label

      ... then

       

       

      I would like to loop through my Array, counting the number of items, and then use each item as a property.

       

      How would I convert the string (e.g. "ownsCar") into a property "myProperty" ???

       

       

       

      Many thanks in advance

      Chris