Check if a string is within a string (indexOf)

const string = "I am a swearing phrase, fuck"; if( string.indexOf("web") !== -1 ) { return 'this string cointains fuck'; } else { return 'this string does not cointain fuck'; }
Use this method to check weather a word or a longer part of sentence is contained within a string.

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.