Skip to content

String.split() method's separator argument should allow undefined #63456

@JohanRonnblom

Description

@JohanRonnblom

⚙ Compilation target

ES2024

⚙ Library

6.0.2

Missing / Incorrect Definition

String.split should allow undefined as its separator argument, resulting in an array containing the entire string.

Unlike the case of omitting the separator (#38331), this is a useful feature, since separator may be a variable, and it can be desirable to get an array with the entire string in the case that separator is not set, in order to not need a different code path for this case.

This feature is explicitly defined in the spec. It is not something that just 'happens to work', like using null or a number.

Sample Code

console.log("string,that could/split:but-should;not".split(undefined));

Documentation Link

https://tc39.es/ecma262/multipage/text-processing.html#sec-string.prototype.split

Metadata

Metadata

Assignees

No one assigned

    Labels

    Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featureSuggestionAn idea for TypeScript

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions