String Search

We are checking the presence of a sub string https:// inside a main string. We used if else condition checking to display a message based on the returned value. Here is the code.
var my_str="Welcome to"
var str="https://";
document.write (;

document.write(my_str.indexOf("Not Found inside string"));}
else{document.write("Found: the location of the sub string is ");
document.write (;
WE can search for presence of a string inside a main string in client side JavaScript by using function.

If the search string is found inside the main string then it will return the position or the index of the location of the string.

Note that the index of first letter is 0. If the string is not found inside the main string then it returns -1.
JavaScript String Reference Search & replace string in JavaScript Uppercase to lower case by toLowerCase() method
Subscribe to our YouTube Channel here


* indicates required
Subscribe to plus2net




    Post your comments , suggestion , error , requirements etc here

    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 All rights reserved worldwide Privacy Policy Disclaimer