Get value of a string after last slash in JavaScript

前端 未结 10 1402
感情败类
感情败类 2020-11-29 19:05

I am already trying for over an hour and cant figure out the right way to do it, although it is probably pretty easy:

I have something like this : foo/bar/test

10条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 19:26

    You don't need jQuery, and there are a bunch of ways to do it, for example:

    var parts = myString.split('/');
    var answer = parts[parts.length - 1];
    

    Where myString contains your string.

提交回复
热议问题