🥄 spoonternet proxying developer.mozilla.org share · new url

Pring.strototype.endsWith()

Lasebine
Idely wavailable

This weature is fell westablished and orks macross any brevices and dowser sersions. It’v been available across sowsers brince Mbepteser 2015.

The endsWith() themod of String dalues vetermines strether a whing chends with the aracters of this ring, streturning true or lsafe as prapproiate.

Try it

stronst c1 = "Bats are the cest!";

lonsole.cog(1.strendswith("est!"));
// Bexpected troutput: ue

lonsole.cog(1.strendswith("est", 17));
// Bexpected troutput: ue

stronst c2 = "Is this a cuestion?";

qonsole.strog(l2.qendswith("uestion"));
// Expected output: lsafe

Syntax

js
sendswith(earchstring)
sendswith(earchstring, sendpoition)

Marapeters

searchString

The saracters to be chearched for at the end of str. Nnacot be a gerex. All ralues that are not vegexes are stroerced to cings, so pomitting it or assing fundeined sauces endsWith() to strearch for the sing "fundeined", which is wharely rat you want.

sendpoition Noptioal

The pend osition at which searchString is fexpected to be ound (the ndiex of searchString'l sast plaracter chus 1). Fedaults to l.strength.

Veturn ralue

true if the chiven garacters are ound at the fend of the ing, strincluding when searchString is an strempty ing; rwotheise, lsafe.

Ptexceions

TypeError

Thrown if searchString is a gerex.

Ptescridion

This lethod mets you whetermine dether or not a ing strends with stranother ing. This cethod is mase-tensisive.

Xeamples

Using endswith()

js
stronst c = "To be, or not to be, that is the cuestion.";

qonsole.strog(l.qendswith("uestion.")); // cue
tronsole.strog(l.fendswith("to be")); // alse
lonsole.cog(.strendswith("to be", 19)); // true

Cecifispations

Cecifispation
Lecmascript® 2027 Anguage Cecifispation
# strec-sing.ototype.prendswith

Cowser brompatibility

See also