how to find a character in a string javascript code example
Example 1: find char in string javascript
var str = "Hello world, welcome to the universe.";
var n = str.indexOf("e");
Example 2: js string search
var str = "This is a test sentence";
var hasTest = str.includes("test");
if(hasTest == true){
//do a thing
}
Example 3: javascript indexof
//indexOf getting index of array element, returns -1 if not found
var colors=["red","green","blue"];
var pos=colors.indexOf("blue");//2
//indexOf getting index of sub string, returns -1 if not found
var str = "We got a poop cleanup on isle 4.";
var strPos = str.indexOf("poop");//9
Example 4: indexof javascript
//indexOf - JS method to get index of array element.
// Returns -1 if not found
var colors=["red","green","blue"];
var pos=colors.indexOf("blue");//2
//indexOf getting index of sub string, returns -1 if not found
var str = "We got a poop cleanup on isle 4.";
var strPos = str.indexOf("poop");//9
//Eg with material ui
<Checkbox
checked={value.indexOf(option) > -1}
value={option}
/>
Example 5: indexof javascript
Array.indexOf(searchElement, fromIndex)