# oxc/uninvoked-array-callback

> Disallow array methods with a callback directly on `new Array(n)`

`new Array(5)` has a length of 5 but no elements, only empty slots. `map`, `forEach`, `filter`, and most other array methods skip empty slots, so the callback never runs. `new Array(5).map(() => 0)` gives back five empty slots, not five zeros.

The rule reports a method call directly on `new Array(n)`, where `n` is a number written in the code and the first argument is a function written in the call. It doesn't look at the method name. `find()` and `findIndex()`, which do visit empty slots, are reported too, and so is `fill(() => 0)`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"oxc/uninvoked-array-callback" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```js
const scores = new Array(5).map(() => 0);
```

{/* bad */}
```js
new Array(3).forEach(function () {
  addRow();
});
```

Not reported:

{/* good */}
```js
const scores = Array.from({ length: 5 }, () => 0);
```

`fill()` puts a value in every slot, so the methods after it see all of them:

{/* good */}
```js
const indexes = new Array(5).fill(0).map((_, index) => index);
```

{/* good */}
```js
for (let row = 0; row < 3; row++) {
  addRow();
}
```
