Solution: 1
If you want to check whether a string contains a specific character or substring in JavaScript, you can use the indexOf() method. [See documentation here.]
However, if your goal is to search the entire page for text, you can use jQuery’s :contains() selector. [See jQuery docs.]
Example:
var has_string = $('*:contains("search text")');
If the selector returns elements, that means the text exists on the page.
For instance:
var has_string = $('*:contains("Alex JL")').length;
// has_string is 18
var has_string = $('*:contains("horsey rodeo")').length;
// has_string is 0
So you can simply wrap this in an if condition to check whether the text is present.