Skip to content

.fill() value is optional in JS #25392

@BnayaZil

Description

@BnayaZil

I'm really sorry if it's duplication but I couldn't find existing issue.

Code

new Array(3).fill()

Expected behavior:
The JS output for this is just:

[undefined, undefined, undefined]

I know there are more ways to fill dynamic empty array probably better ways but this use case serves many people in order to accomplish something like:

new Array(15).fill().map((v, i) => ({_id: `${i}`}))

Actual behavior:
Throwing the following error: "Expected 1-3 arguments, but got 0"

I will be glad to create a PR to migrate the definition of value property to optional.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions