search string javascript code example
Example 1: js indexof regex
//regular indexof
let a = 'asbdais sbbdias isajdij';
a.indexOf('ias');
// with regex:
let a = 'asbdais sbbdias isajdij';
a.search(/ias/g);
Example 2: js string search
var str = "This is a test sentence";
var hasTest = str.includes("test");
if(hasTest == true){
//do a thing
}
Example 3: search inside a string javascript
var string = "Hello world!";
var n = string.search("w"); //now n equals 6