Skip to content

Splice on data with a single argument throws an error. #12191

Description

@g-regor

Expected behavior

Calling splice with a single argument (.splice(0)) on data should clear the array.
The second argument is optional.

Current behavior

Instead it throws an error:

Uncaught RangeError: Invalid array length

Reproducible sample

https://jsfiddle.net/1trhp2kf/

Possible solution

This can be circumvented by providing the second argument:

.splice(0, Infinity)

The problem seems to be with this line.

const newCount = arguments.length - 2;

When there is only one argument, newCount becomes -1, which in an invalid length.

chart.js version

v4.5.1

Activity

  1. added a commit that references this issue on Feb 14, 2026
    d9b3165
  2. added a commit that references this issue on Feb 22, 2026
    38e64b7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions