HI WELCOME TO KANSIRIS

Check if a string has a certain piece of text

Leave a Comment

Here you go: ES5
var test = 'Hello World';
if( test.indexOf('World') >= 0){
  // Found world
}
With ES6 best way would be to use includes function to test if the string contains the looking work.
const test = 'Hello World';
if (test.includes('World')) { 
  // Found world
}

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.