javascript substring match code example
Example 1: check for substring javascript
const string = "javascript";
const substring = "script";
console.log(string.includes(substring));
Example 2: check if word is in string javascript
var str = "Hello world, welcome to the universe.";
var n = str.includes("world");
Example 3: javascript contains substring
var str = "We got a poop cleanup on isle 4.";
if(str.indexOf("poop") !== -1){
alert("Not again");
}
Example 4: match substring js
const string = "foo";
const substring = "oo";
console.log(string.includes(substring));
Example 5: .includes( string
var str = "Hello world, welcome to the universe.";
var n = str.includes("world");
Example 6: how to use the match function in javascript for regex
const str = 'For more information, see Chapter 3.4.5.1';
const re = /see (chapter \d+(\.\d)*)/i;
const found = str.match(re);
console.log(found);