Reputation: 4097
Here is my javascript:
var error_msg = error_data.validation_msg;
if(error_msg)
{
for(var i=0; i<5; i++)
{
var answer_exact = 'answer_exact_'+i;
var error = error_msg.answer_exact;
}
}
How I can call objects in error_msg class like:
error_msg.answer_exact_0;
error_msg.answer_exact_1;
error_msg.answer_exact_2;
....
Upvotes: 0
Views: 29
Reputation: 388316
You need to use bracket notation to get a property using a dynamic key(where the property name is stored in a variable).
var error = error_msg[answer_exact];
Your code tries to read a property named answer_exact
from the object error_msg
Upvotes: 3