dimanche 23 août 2020

Why are items inside an Array() dependent? (Javascript)

I did:

a = Array(2).fill([]);
a[0].push(1);

Expected outcome: a = [[1], []] Got: a = [[1], [1]]

Why does the second item depend on the first one here?

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire