js list assignment problem

After the js list is generated, after reassigning a certain position:

let a=[]
for(let i=0;i<7;i++){
    
    
	a.push('')
}
a[2]=4

There may be a strange phenomenon:
console.log printing is normal, but not normal after expansion:
insert image description here
the consequence is that when this list is assigned to other objects, the attached value is abnormal:

obj={
    
    }
obj['a']=a
console.log(obj)
{
    
    ["",0,"","","","".""]}

The solution is to use JSON.stringify() and JSON.parse() to assign new data:

let b=JSON.stringify(a)
let c=JSON.parse(b)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324343372&siteId=291194637