Javascript Does String Contain Substring

By Forrest Smith - Drempd.com

var str = "Some haystack text goes here that contains needlestring";

  str.includes('needlestring');




If you get an error, like "TypeError: e.includes is not a function", it probably means that you're trying to do a search on something that isn't a string or an array.   Fix this by converting the variable to a string, like:



element.toString().includes("#");