find character in string code example

Example 1: 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 2: string .find in c++

std::string t = "Banana Republic";
std::string s = "nana";

std::string::size_type i = t.find(s);

if (i != std::string::npos)
   t.erase(i, s.length());

Example 3: indexof javascript

Array.indexOf(searchElement, fromIndex)

Example 4: find in string c++

size_t find (const string& str, size_t pos = 0) const;