Js for cycle problem

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!

Mar.21,2021
The

object is of reference type;


because page_ary [0] = page_ary [1] = page_ary [2] = obj


for loop ends, the
object is outside the loop (another object and will be referenced). If you don't use an object, you won't have a problem.) all you get in the end is data from iTunes 3.
so you need to put the declaration of obj in the loop. At the end of each loop, the obj object will be reconstructed so that there will be no reference problems, and the assignment will be OK.

Menu