If a sentence contains "Hello World" (no quotes) then I need to return true and do something. Possible sentences could be like this:
var sentence = "This is my Hello World and I like widgets." var sentence = "Hello World - the beginning of all" var sentence = "Welcome to Hello World" if ( sentence.contains('Hello World') ){ alert('Yes'); } else { alert('No'); }
I know the .contains does not work, so I'm looking for something does work. Regex is the enemy here.
The method you're looking for is indexOf
(Documentation). Try the following
if (sentence.indexOf('Hello World') >= 0) { alert('Yes'); } else { alert('No'); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With