JS remove everything after the last occurrence of a character

前端 未结 9 1855
梦如初夏
梦如初夏 2020-12-11 16:47

Okay I have this

var URL = \"http://stackoverflow.com/questions/10767815/remove-everything-before-the-last-occurrence-of-a-character\";
console.log(URL.subst         


        
9条回答
  •  死守一世寂寞
    2020-12-11 17:36

    Here you are:

    var URL = "http://stackoverflow.com/questions/10767815/remove-everything-before-the-last-occurrence-of-a-character";
    alert(URL.substring(0, URL.lastIndexOf("/") + 1));

    Hope this helps.

提交回复
热议问题