find string js code example

Example 1: if string javascript

if (typeof myVar === 'string') { /* code */ };

Example 2: find in string javascript

stringToBeSearched.search(stringToBeFound);

Example 3: js string search

var str = "This is a test sentence";
var hasTest = str.includes("test");

if(hasTest == true){
	//do a thing 
}

Example 4: string.find javascript

var index = string.indexOf(searchStr);
var index = string.search(searchStr);

Example 5: reverse string js

function reverseString(str) {
    var newString = "";
    for (var i = str.length - 1; i >= 0; i--) {
        newString += str[i];
    }
    return newString;
}
reverseString('hello');