What gets logged?
const array = new Array(3).fill([])
array[0].push("bytes")
console.log(array) // [ ["bytes"], ["bytes"], ["bytes"] ]
The key to understanding this one is in knowing that arrays in JavaScript are reference values.
When you call .fill([])
, what you’re really doing is “filling up” the array with three references to the same array. You can kind of think of it like this.