jquery - Iterate through javascript object with generated variable names -
I'm trying to iterate through a javascript object (using jQuery) in a bunch of variables, Every variable name that was returned without JSON is to be specified.
I want to loop through the following elements of an object and testing their values:
obj.pract_0 obj.pract_1 obj .pract_2 obj. Pract_3 .. obj.pract_100
The method I am trying to do is:
for (var i = 0; i & lt ; 10; i ++) {var purse_num = ++ window ['obj.pract_' + i]; If (practice_num == 1) {var parent = '# pect_' + i; $ (Practice) .attr ('check', 'check'); }}
I am getting an AN from this, but there is another way to do this? My problem is obviously var pract_num = ++ window [obj.pract_ '+ i];
and I'm not sure I'm doing it correctly.
I do not need to modify the code that generates JSON, though I'm pretty sure how do I do it.
window ...
var obj = window ['myObj Instead of going directly through 'reference obj'
']; // If necessary (var i = 0; i & lt; 10; i ++) {var purse_name = ++ obj ['practice_' + i]; // Magic if (pract_num == 1) {var parent = '# pect_' + i; $ (Practice) .attr ('check', 'check'); }}
You are receiving NaN
because you try to increment ( ++
) in the context of some non-numeric Are there.
Comments
Post a Comment