# no-associative-arrays

Rule `sonarjs/no-associative-arrays`. Array indexes should be numeric

- Source: sonarjs
- Technologies: JavaScript
- Kind: style
- Needs type information: yes
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1242 by reach, #543 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/no-associative-arrays` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-3579/) |

## Code examples

### Incorrect: the rule reports this

```js
let arr = [];
arr[0] = 'a';
arr['name'] = 'bob';  // Noncompliant
arr[1] = 'foo';
```

### Correct: the rule accepts this

```js
let obj = {
  name: 'bob',
  arr: ['a', 'foo']
};
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/no-associative-arrays": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/no-array-delete](https://lintradar.dev/rules/sonarjs/no-array-delete.md): "delete" should not be used on arrays
- [sonarjs/no-async-constructor](https://lintradar.dev/rules/sonarjs/no-async-constructor.md): Constructors should not contain asynchronous operations
- [sonarjs/no-angular-bypass-sanitization](https://lintradar.dev/rules/sonarjs/no-angular-bypass-sanitization.md): Angular built-in sanitization should not be disabled
- [sonarjs/no-case-label-in-switch](https://lintradar.dev/rules/sonarjs/no-case-label-in-switch.md): "switch" statements should not contain non-case labels
- [sonarjs/no-alphabetical-sort](https://lintradar.dev/rules/sonarjs/no-alphabetical-sort.md): "Array.prototype.sort()" and "Array.prototype.toSorted()" should use a compare function
- [sonarjs/no-clear-text-protocols](https://lintradar.dev/rules/sonarjs/no-clear-text-protocols.md): Clear-text protocols should not be used

---

Web page: https://lintradar.dev/rules/sonarjs/no-associative-arrays. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
