Use indexOf("searchString") to find a string in a Glide list

Use indexOf("searchString") to return the location of the string passed into the method if the glide list field, such as a Watch list, has at least one value in it.

If the field is empty, it returns undefined. To avoid returning an undefined value, do any of the following:

  • Force the field to a string, such as: watch_list.toString().indexOf("searchString")
  • Check for an empty Glide list field with a condition before using indexOf(), such as: if (watch_list.nil() || watch_list.indexOf("searchString") == -1)