Symbol.split

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

Die statische Dateneigenschaft Symbol.split repräsentiert das bekannte Symbol Symbol.split. Die Methode String.prototype.split() sucht dieses Symbol in ihrem ersten Argument, um die Methode zu finden, die einen String an den Indizes teilt, die mit dem aktuellen Objekt übereinstimmen.

Für weitere Informationen siehe RegExp.prototype[Symbol.split]() und String.prototype.split().

Probieren Sie es aus

class Split1 {
  constructor(value) {
    this.value = value;
  }
  [Symbol.split](string) {
    const index = string.indexOf(this.value);
    return `${this.value}${string.substring(0, index)}/${string.substring(
      index + this.value.length,
    )}`;
  }
}

console.log("foobar".split(new Split1("foo")));
// Expected output: "foo/bar"

Wert

Das bekannte Symbol Symbol.split.

Eigenschaften von Symbol.split
Schreibbarnein
Aufzählbarnein
Konfigurierbarnein

Beispiele

Benutzerdefinierte Umgekehrte Teilung

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

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

Spezifikationen

Specification
ECMAScript® 2026 Language Specification
# sec-symbol.split

Browser-Kompatibilität

Siehe auch