How To Use String Object Search In JavaScript

In this article I am going to explain about String Object Search In JavaScript.
  • 1406

Use search() method in JavaScript

The search() method searches a string for a specified value.

This method returns a position of the match string from the given character set.

When the string is not match, then method is return -1.

All browsers support string object search() method.



<!DOCTYPE html>


<body style ="background-color :Red">


<p id="demo">Display the position of the match.</p>


<button onclick="myFunction()">Click here</button>


<script type="text/javascript">

    function myFunction() {

        var str = "Visit dotnetheaven!";

        var n ="dotnetheaven");

        document.getElementById("demo").innerHTML = n;










Further Readings

You may also want to read these related articles :here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here


More Articles

© 2020 DotNetHeaven. All rights reserved.