Rowanto Luo

Just another blog. or log.

Tag: fill array with empty array

  1. JavaScript, beware of filling an array with empty array.

    I love JavaScript, however very often, it doesn't love me back. const dataBuffers = new Array(4); dataBuffers.fill([]); for (let i = 0; i < 4; i += 1) { dataBuffers[i].push(7); } console.log(JSON.stringify(dataBuffers)); // guess what is the answer? If you guess the answer would be [[7],[7]…

    javascript, array, empty array, fill array with empty array