str.endsWith(searchString)
determines whether str
ends with searchString
the 1st parameter the string to search for
- can be a character
- can be a string
- can contain unicode characters
- a regular expression throws a TypeError
the 2nd parameter, the position where the search ends (as if the string was only that long)
- find "el" at a substring of the length 2
undefined
uses the entire string- the parameter gets coerced to an integer (e.g. "5" becomes 5)
value less than 0
- returns
true
, when searching for an empty string - return
false
, when searching for a non-empty string
this functionality can be used on non-strings too
- e.g. a boolean
- e.g. a number
- also using the position works
Links
The official specification, actually quite good to read for this function.
The Mozilla Developer Network docs, contains some examples.