var page_ary=[];
var obj={};
//var j=0;
for(var i=1;i<=3;iPP){
obj.page=i;
obj.cla="";
//j=i;
console.log("i","---",i);
console.log("obj","---",obj);
page_ary[i-1]=obj;
console.log("page_ary","---",page_ary);
}
printed page_ary
{page: 3, cla: ""}
{page: 3, cla: ""}
{page: 3, cla: ""}
if you put the obj declaration in it
var page_ary=[];
//var j=0;
for(var i=1;i<=3;iPP){
//
var obj={}
obj.page=i;
obj.cla="";
//j=i;
console.log("i","---",i);
console.log("obj","---",obj);
page_ary[i-1]=obj;
console.log("page_ary","---",page_ary);
}
that"s the print result
{page: 1, cla: ""}
{page: 2, cla: ""}
{page: 3, cla: ""}
who can explain why? Thank you!