Baseline Widely available
The Symbol.search
static data property represents the well-known symbol Symbol.search
. The String.prototype.search()
method looks up this symbol on its first argument for the method that returns the index within a string that matches the current object.
For more information, see RegExp.prototype[Symbol.search]()
and String.prototype.search()
.
class Search1 {
constructor(value) {
this.value = value;
}
[Symbol.search](string) {
return string.indexOf(this.value);
}
}
console.log("foobar".search(new Search1("bar")));
// Expected output: 3
Value
The well-known symbol Symbol.search
.
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
Specifications Browser compatibility See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3