# prefer-array-slice πŸ“ Prefer `Array#slice()` over `Array#splice()` when reading from the returned array. πŸ’ΌπŸš« This rule is enabled in the βœ… `recommended` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config). This rule is _disabled_ in the β˜‘οΈ `unopinionated` [config](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config). πŸ’‘ This rule is manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions). Prefer `Array#slice()` over `Array#splice()` when reading from the returned array. `Array#splice()` mutates the source array. When the returned elements are immediately indexed or read with `.at()`, `Array#slice()` expresses the read-only intent without changing the source array. ## Examples ```js // ❌ const foo = process.argv.splice(2)[0]; // βœ… const foo = process.argv.slice(2)[0]; ``` ```js // ❌ const foo = array.splice(index).at(0); // βœ… const foo = array.slice(index).at(0); ``` ```js // βœ… array.splice(index); ``` ```js // βœ… array.splice(index, deleteCount)[0]; ``` Keep `Array#splice()` when intentional mutation is part of the operation.