Skip to content

oxc/bad-array-method-on-arguments Correctness

This rule is turned on by default.

What it does

This rule applies when an array method is called on the arguments object itself.

Why is this bad?

The arguments object is not an array, but an array-like object. It should be converted to a real array before calling an array method. Otherwise, a TypeError exception will be thrown because of the non-existent method.

Example

javascript
function add(x, y) {
  return x + y;
}
function sum() {
  return arguments.reduce(add, 0);
}

References

Released under the MIT License.