← TechnologyThe essentials of

fill(): same value can mean one shared object

Publisher: ResumeMaker • 1 source

Published: 22 Oct 2026 13:13 · Updated: 22 Oct 2026 13:13

AI source check: 21 Oct 2026 12:40. This is not editorial approval.

In a few sentences

In brief

Filling an array does not create an independent copy for each position.

Useful to know

fill() records one value in a selected array range. In Array(3).fill(0), you get three zeroes. In Array(3).fill({count: 0}), the three positions point to the same object . [1]

If you change count in the first position, the change is also visible in the others. For independent records, create a new object for each position, for example, Array.from({length: 3}, () => ({count: 0})). The difference is important for forms and tables, where editing one line does not have to change all.

Sources

For further detail and to check the information:

  1. [1] MDN — Array.fill ↗