JavaScript Symbol.search Property

The JavaScript Symbol.search symbol identifies the method responsible for returning the position of the first match of a regular expression within a string.

Syntax

Example

[Symbol.search](string)

Parameters

String.

Return value

The position of a string.

Browser Support

Chrome 32
Safari 8
Firefox 29
Opera 19

Example 1

Example

<script>

//JavaScript to illustrate Symbol.search

class S {  

constructor(value) 

{

    this.value = value;

  }

  [Symbol.search](string) {

return string.indexOf(this.value);

  }

}

document.write('Example'.search(new S('int')));

//expected output: 7

</script>

Output:

Example 2

Example

<script>

//JavaScript to illustrate Symbol.search

class S {  

constructor(value) 

{

    this.value = value;

  }

  [Symbol.search](string) {

return string.indexOf(this.value);

  }

}

document.write('Symbol'.search(new S('ol')));

//expected output:4

</script>

Output:

Input Required

This code uses input(). Please provide values below: