I am not sure if I am using the correct terms for what I am trying to do so please excuse that.
Mootools More has an Fx.Elements class that allows you to tween a collection of elements. The set method of the class only accepts an object and allows me to set the original values, however I am not sure how many elements I’ll be having to tween as the HTML will be generated dynamically.
Here is my theory of what I want to do:
var n = $$('.element').length; // 5
var myObj = {};
var value = 0;
var i;
for (i = 0; i < n; i++) {
myObj = {
i: { property : value }
}
}
console.log(myObj);
// What I get:
// Object { i : { property: 0 } }
// What I would like:
// Object {
// 0 : { property : 0
// },
// 1 : { property : 0
// },
// 2 : { property : 0
// },
// 3 : { property : 0
// },
// 4 : { property : 0
// }
// }
The above, obviously, only sets the i property of the object 5 times. I need i to iterate upwards.
I hope I have explained better than I think I have!
When using the object literal syntax keys are always treated as strings – even without quotes. Besides that, you overwrite the whole object everytime.
This code does what you want. Note that I changed it to
i < nsince you’ll geti = 5in the last loop which does not fit to the example you posted.