Symbol.split

O Symbol.split é um símbolo conhecido que especifica o método que divide uma string nos índices correspondentes a uma expressão regular. Essa função é chamada pelo método String.prototype.split().

Para mais informações, veja RegExp.prototype[@@split]() (en-US) e String.prototype.split().

Experimente

Property attributes of Symbol.split
Writable no
Enumerable no
Configurable no

Exemplos

Divisão reversa personalizada

js
class ReverseSplit {
  [Symbol.split](string) {
    const array = string.split(" ");
    return array.reverse();
  }
}

console.log("Another one bites the dust".split(new ReverseSplit()));
// resultado esperado: [ "dust", "the", "bites", "one", "Another" ]

Especificações

Specification
ECMAScript Language Specification
# sec-symbol.split

Compatibilidade com navegadores

BCD tables only load in the browser

Veja também