A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search below:

Symbol.search - JavaScript | MDN

Symbol.search

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().

Try it
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.

Writable no Enumerable no Configurable no Examples Custom string 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