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 September 2015.
Die Symbol.split
statische Dateneigenschaft repräsentiert das bekannte Symbol Symbol.split
. Die Methode String.prototype.split()
sucht dieses Symbol im ersten Argument, um die Methode zu finden, die einen String an den Indizes aufteilt, die mit dem aktuellen Objekt übereinstimmen.
Weitere Informationen finden Sie unter 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 | |
---|---|
Schreibbar | nein |
Aufzählbar | nein |
Konfigurierbar | nein |
Beispiele
Benutzerdefiniertes reverses Split
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® 2025 Language Specification # sec-symbol.split |
Browser-Kompatibilität
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
split |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support