π Prefer Array#slice() over Array#splice() when reading from the returned array.
πΌπ« This rule is enabled in the β
recommended config. This rule is disabled in the βοΈ unopinionated config.
π‘ This rule is manually fixable by editor 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.
// β
const foo = process.argv.splice(2)[0];
// β
const foo = process.argv.slice(2)[0];// β
const foo = array.splice(index).at(0);
// β
const foo = array.slice(index).at(0);// β
array.splice(index);// β
array.splice(index, deleteCount)[0];Keep Array#splice() when intentional mutation is part of the operation.