Possible Duplicate:
How do I add a property to a Javascript Object using a variable as the name?
Dynamic property names for loop of object Javascript
In success of javascript function I receveing data and it look like this:
data.lvl1
data.lvl2
data.lvl3
...
let say I have only 3 elements in data and I would like to loop for each of them and rise alert for every level:
for(a = 1; a<= 3; a++)
{
alert(data.lvl + a);
//I would like to read lvl1, lvl2, lvl3
}
This approach is obviously wrong.
Please explain how to reach lvl1, lvl2 in loop when lvl number is based on increasing a
.