We have an empty object:
var obj = {};
I would like to make a for loop which with each iteration adds a new obj = {value: i, next: i+1}
We have an empty object:
var obj = {};
I would like to make a for loop which with each iteration adds a new obj = {value: i, next: i+1}
Simply use an array of objects and for every iteration push this values on it:
var obj=[];
for(var i=1;i<10;i++){
obj.push({value: i, next: i+1});
}
This is a DEMO Fiddle.
For each iteration give the obj.value
and the obj.next
, take a look at JavaScript Object Properties for futher information.
Not that sure what you mean but what about this
var obj = [];
function Obj(i){
this.value = i;
this.next = i+1;
}
for (var i= 0;i<10;i++){
obj.push(new Obj(i));
}
Instead of an object of objects an array of them