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.
Le symbole connu Symbol.split
définit la méthode qui est utilisée pour découper une chaîne de caractères à l'emplacement où une correspondance a été trouvée grâce à une expression rationnelle. Cette fonction est appelée par la méthode String.prototype.split()
.
Pour plus d'informations, se référer aux pages sur RegExp.prototype[@@split]()
et String.prototype.split()
.
Exemple interactif
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"
Attributs de Symbol.split | |
---|---|
Écrivable | Non |
Énumérable | Non |
Configurable | Non |
Spécifications
Specification |
---|
ECMAScript® 2025 Language Specification # sec-symbol.split |
Compatibilité des navigateurs
BCD tables only load in the browser