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.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ead8a1-2161.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ead8a1-2161.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?