更新时间:2023-01-28 13:03:26
如果你正在寻找路径中的最后一项,试试这个:
If you're looking for the last item in the path, try this:
var current_path = window.location.pathname.split('/').pop();
这个:
window.location.pathname
会给你类似的东西:
"/questions/6543242/how-to-extract-the-filename-of-url-in-javascript"
然后 .split()
会将字符串拆分为数组,并且 .pop()
将为您提供数组中的最后一项。
Then the .split()
will split the string into an Array, and .pop()
will give you the last item in the Array.