How to Check Whether a String Contains a Substring in JavaScript

From WikiOD

By Using String.prototype.includes

Method 1[edit | edit source]

const string = "wikiod";
const substring = "wiki";

console.log(string.includes(substring));
// true

Method 2[edit | edit source]

var string = "wikiod";
var substring = "wikiod";

console.log(string.indexOf(substring) !== -1);
// true