Wednesday, November 19, 2025
HomeLanguagesJavascriptJavaScript Symbol search Property

JavaScript Symbol search Property

JavaScript Symbol search property determines the method that returns the index within a string that matches the regular expression. This function is called by the String search() method.

Syntax:

[Symbol.search](string)

Parameters: It accepts single parameter “String”.

Return value: This returns the position of a string where it matches and if not matches it will return -1.

Below examples illustrate the Symbol search property in JavaScript:

Example 1:




<script>
// JavaScript example to illustrate
// Symbol.search property
class obj {
    constructor(value) {
            this.value = value;
        }
        [Symbol.search](string) {
            return string.indexOf(this.value);
        }
}
  
console.log('Geeksforneveropen'.search(new obj('Geek')));
console.log('Geeksforneveropen'.search(new obj('geek')));
</script>


Output:

0
8

Example 2:




<script>
// JavaScript program to illustrate
// the Symbol.search property
class S {
    constructor(value) {
            this.value = value;
        }
        [Symbol.search](string) {
            return string.indexOf(this.value);
        }
}
console.log('GEEKSFORGEEKS'.search(new S('geek')));
console.log('GEEKSFORGEEKS'.search(new S('Geek')));
</script>


Output:

-1
-1

Supported Browsers: The browsers supported by Symbol search property are listed below:

  • Google Chrome 50 and above
  • Firefox 49 and above
  • Edge 79 and above
  • Opera 37 and above
  • Apple Safari 10 and above

We have a complete list of Javascript symbols’ properties and methods, to check those please go through the Javascript Symbol Complete Reference article.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32404 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6775 POSTS0 COMMENTS
Nicole Veronica
11924 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11994 POSTS0 COMMENTS
Shaida Kate Naidoo
6903 POSTS0 COMMENTS
Ted Musemwa
7159 POSTS0 COMMENTS
Thapelo Manthata
6859 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS