I am new to javascript and I am having this really simple problem.
var counters = [];
for (var i = 0; i < 3; i++) {
counters.push[i];
}
alert(counters.length);
This code is expected to alert 3, but the real result is 0. Can someone please this to me. I'm not really sure how to ask about this error. Thanks
Sorry for this question.. I have fixed it. Thanks for answering
I can't ask another quesition yet since not enough karma.. But My real problem is this
for (var i = 0; i < 2; i++) {
if (i == 1) {document.write(" <tr class='noBorder' onclick='alert(i)');}
if (i == 0){ document.write(" <tr class='noBorder' onclick='alert(i)');}
}
Whenever I click on a row, the alert results in 2. It's basically this question, but in html Passing parameter onclick, in a loop