Symbol.split
Symbol.split
ウェルノウンシンボルは、正規表現に一致する位置で文字列を分割するメソッドを指定します。この関数は String.prototype.split()
メソッドによって呼び出されます。
詳しくは、 RegExp.prototype[@@split]()
と String.prototype.split()
を参照してください。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
Symbol.split のプロパティ属性 |
|
---|---|
書込可能 | 不可 |
列挙可能 | 不可 |
設定可能 | 不可 |
例
独自の逆方向の分割
class ReverseSplit {
[Symbol.split](string) {
const array = string.split(' ');
return array.reverse();
}
}
console.log('Another one bites the dust'.split(new ReverseSplit()));
// expected output: [ "dust", "the", "bites", "one", "Another" ]
仕様書
ブラウザーの互換性
BCD tables only load in the browser