javascript - Object in class set as variable -


here 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 can call objects in error_msg class like:

error_msg.answer_exact_0; error_msg.answer_exact_1; error_msg.answer_exact_2; .... 

you need use bracket notation property using dynamic key(where property name stored in variable).

var error = error_msg[answer_exact]; 

your code tries read property named answer_exact object error_msg


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -