如何在JavaScript中获取字符串的最后一部分?
问题描述:
我的网址将如下所示:
http://www.example.com/category/action
如何获得行动一词。 url的最后一部分(在最后一个正斜杠/之后)每次都会有所不同。那么无论是行动还是冒险等,我怎样才能在最后一次收盘前斜线后得到这个词?
How can I get the word "action". This last part of the url (after the last forward slash "/") will be different each time. So whether its "action" or "adventure", etc. how can I always get the word after the last closing forward slash?
答
单向:
var lastPart = url.split("/").pop();