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.
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.
Share Improve this question asked Apr 21, 2020 at 8:42 Himanshu RanjanHimanshu Ranjan 1251 gold badge1 silver badge7 bronze badges 2-
2
!x.startsWith(y)
– VLAZ Commented Apr 21, 2020 at 8:43 -
why not test logical NOT
!
? – Nina Scholz Commented Apr 21, 2020 at 8:43
1 Answer
Reset to default 12Use startsWith
with the string you want to check against, then invert the check with !
:
if (!str.startsWith('foo')) {
// string does not start with foo
}