I have a string btnHome
. How can I remove btn
and only get Home
from it in javascript / jQuery?
I used slice like str.slice(3, -1)
but it gives me Hom
whereas I need Home
.
Remove the -1
part (just use str.slice(3)
).
The -1
argument says slice to 1 character from the end of the string .
Try like
alert(str.slice(3));
Need not to give -1
there.So it will slice it from starting
of the string.
两种简单的方法可以做到这一点:
str.split('btn')[1]; // Home
str.slice(3); // Home
您应该使用substr()方法:
target.substr(3);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.