Skip to content

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

@g-regor

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions