JS remove everything after the last occurrence of a character

前端 未结 9 1842
梦如初夏
梦如初夏 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:22

    var URL = "http://stackoverflow.com/questions/10767815/remove-everything-before-the-last-occurrence-of-a-character";
    
    console.log(URL.substring(0,URL.lastIndexOf('/')+1));
    //The +1 is to add the last slash
    

提交回复
热议问题