Opposite Method of startsWith() in Javascript
I Know What startsWith() Does in Js. Is There a Method That Checks Opposite of What startsWith() Does? ? Something Like "Notstartswith()". I Want a Method That...
I know what startsWith() does in js. Is there a method that checks opposite of what startsWith() does?? Something like "notstartsWith()". I want a method that would return false if a string starts with a pattern and true if it doesn't.
1 Answer
Use startsWith with the string you want to check against, then invert the check with !:
if (!str.startsWith('foo')) {
// string does not start with foo
}