# unicorn/no-array-method-this-argument

> Disallow the `thisArg` argument of array methods such as `map` and `filter`

`map`, `filter`, and similar methods take a second argument that becomes `this` inside the callback. It comes after the callback, where it's easy to miss. With an arrow function it does nothing, because an arrow function keeps the `this` from the surrounding code.

The rule checks `every`, `filter`, `find`, `findLast`, `findIndex`, `findLastIndex`, `flatMap`, `forEach`, `map`, and `some`. It also checks the third argument of `Array.from()` and `Array.fromAsync()`.

{/* 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]
"unicorn/no-array-method-this-argument" = "error" # or "warn"
```

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

## Examples

Reported:

{/* bad */}
```js
const mine = items.filter(function (item) {
  return item.owner === this.id;
}, user);
```

{/* bad */}
```js
const rows = items.map(table.renderRow, table);
```

{/* bad */}
```js
const cards = Array.from(nodes, function (node) {
  return this.wrap(node);
}, view);
```

Not reported:

{/* good */}
```js
const mine = items.filter((item) => item.owner === user.id);
const rows = items.map((item) => table.renderRow(item));
const cards = Array.from(nodes, (node) => view.wrap(node));
```

The rule skips a call if its first argument can't be a function. It also skips library methods with the same names, such as `_.map()`, `R.map()`, `$.map()`, and `React.Children.map()`, because their second argument means something else:

{/* good */}
```js
const match = collection.find("email", address);
const names = _.map(users, formatName);
```
