Symbol.search
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.
Symbol.search
は静的データプロパティで、ウェルノウンシンボルである Symbol.search
を表します。String.prototype.search()
メソッドは第一引数から、文字列内で現在のオブジェクトに一致する場所を返すメソッドを、このシンボルで探します。
詳しくは、RegExp.prototype[Symbol.search]()
と String.prototype.search()
を参照してください。
試してみましょう
値
ウェルノウンシンボル Symbol.search
です。
Symbol.search のプロパティ属性 | |
---|---|
書込可能 | 不可 |
列挙可能 | 不可 |
設定可能 | 不可 |
例
独自の文字列検索
js
class caseInsensitiveSearch {
constructor(value) {
this.value = value.toLowerCase();
}
[Symbol.search](string) {
return string.toLowerCase().indexOf(this.value);
}
}
console.log("foobar".search(new caseInsensitiveSearch("BaR"))); // 3
仕様書
Specification |
---|
ECMAScript® 2025 Language Specification # sec-symbol.search |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
search |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.