check character in string javascript code example
Example 1: javascript get last character in string
var hello = "Hello World";
var lastCharOfHello=hello.slice(-1);
Example 2: javascript string contains
var string = "foo",
substring = "oo";
console.log(string.includes(substring));
Example 3: javascript check if character exists in string
"FooBar".includes("oo");
"FooBar".includes("foo");
"FooBar".includes("oo", 2);
~"FooBar".indexOf("oo");
~"FooBar".indexOf("foo");
~"FooBar".indexOf("oo", 2);
!!~"FooBar".indexOf("oo");
!!~"FooBar".indexOf("foo");
!!~"FooBar".indexOf("oo", 2);
Example 4: javascript string contains function
s = "Hello world";
console.log(s.includes("world"));
Example 5: javascript string includes
'Blue Whale'.includes('blue')
Example 6: js check if string contains character
"FooBar".includes("oo");
"FooBar".includes("foo");
"FooBar".includes("oo", 2);