---
url: /docs/guide/usage/linter/rules/unicorn/no-confusing-array-with.md
---

### What it does

Disallows confusing uses of [`Array#with()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/with).

### Why is this bad?

`Array#with()` treats a negative index as an offset from the end of the array, unlike
methods such as `slice()` or `splice()`. Using a negative static index is usually a mistake.
Using `.length` as the index always produces `undefined`, since valid indices are
`0 .. length - 1`.

### Examples

Examples of **incorrect** code for this rule:

```javascript
array.with(-1, value);
array.with(array.length, value);
```

Examples of **correct** code for this rule:

```javascript
array.with(array.length - 1, value);
array.with(index, value);
```

## How to use

## Version

This rule was added in v1.73.0.

## References
