I have a string
var s1 = "a,$,b,c";
I want to check if another string ends with s1
So if I send these strings it has to return true
w,w,a,$,b,c
^,^,^,$,@,#,%,$,$,a,$,b,c
a,w,e,q,r,f,z,x,c,v,z,$,W,a,$,b,c
And for these false
a,$,b,c,F,W
a,$,b,c,W
a,$,b,c,$,^,\,/
How can I check it?
Or, less dynamically and more literally:
Using a negative offset for slice() sets the starting point from the end of the string, minus the negative start – in this case, 7 characters (or s1.length) from the end.
slice() – MDC
Adding this to the string prototype is easy: