如何在JavaScript中获取字符串的最后一部分? [英] How to get the last part of a string in JavaScript?

查看:51
本文介绍了如何在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();

这篇关于如何在JavaScript中获取字符串的最后一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆