Below, i shows up as "i", not the number I am iterating through. How do I correct this? Thanks!
for (i = 0; i < 10000; i++) {
var postParams = {
i : 'avalueofsorts'
};
}
for (var i = 0, l = 10000; i < l; ++i) {
var postParams = {};
postParams[i] = 'avalueofsorts'
}
Per Cybernate's comment, you can create the object beforehand and just populate it otherwise you create it each time. You probably want this:
for (var i = 0, l = 10000, postParams = {}; i < l; ++i) {
postParams[i] = 'avalueofsorts'
}
To expand on the 'you want an array comment':
for (var i = 0, postParams = []; i < 10000; i++) {
postParams.push('avalueofsorts');
}
In javascript arrays are just objects with a few extra methods (push, pop etc...) and a length property.
精彩评论