Q:

string includes in js

'Blue Whale'.includes('blue')  // returns false
24
const string = "foo";
const substring = "oo";

console.log(string.includes(substring));
9

var str = "Hello world, welcome to the universe.";

var n = str.includes("world");
 
12
const pets = ['cat', 'dog', 'bat'];

console.log(pets.includes('cat'));
// output: true
20
var str = "We got a poop cleanup on isle 4.";
if(str.indexOf("poop") !== -1){
	alert("Not again");
}
6
if (your_string.indexOf('hello') > -1)
{
  alert("hello found inside your_string");
}
1
let storyWords = ['extremely literally actually hi bye okay']
let unnecessaryWords = ['extremely', 'literally', 'actually' ];

let betterWords = storyWords.filter(function(word) {
  return !unnecessaryWords.includes(word);
});
console.log(betterWords) // ['hi' 'bye' 'okay]
2

New to Communities?

Join the community