0

Is there a way to append a counter to short down a code. So, my code is

  $$("checkbox0").setValue(cookie.checkbox0);
  $$("checkbox1").setValue(cookie.checkbox1);

and so on... What I want to to is for loop

 for(i = 0; i <= columns; i ++) {
     $$("checkbox"+i).setValue(cookie.checkbox[i]);
  }

but it doesn not work for the last checkbox object. Does someone knows the hack for this? Thanks :)

Sale Sasa
  • 21
  • 2
  • 1
    Is that 'checkbox' an array? why checkbox[i]? – Sabith Oct 15 '15 at 09:39
  • 1
    just replace to `$$("checkbox"+i).setValue(cookie["checkbox"+i]);` if checkbox is not array – Sherali Turdiyev Oct 15 '15 at 09:48
  • Possible duplicate of [Dynamically access object property using variable](http://stackoverflow.com/questions/4244896/dynamically-access-object-property-using-variable), although if at all possible it'd be best to use an array instead. – JJJ Oct 15 '15 at 09:54
  • Solved thanks to Juhana javascript master, Thanks! – Sale Sasa Oct 15 '15 at 10:03

0 Answers0