JS remove everything after the last occurrence of a character

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

    Try an array based extraction like

    var URL = "http://stackoverflow.com/questions/10767815/remove-everything-before-the-last-occurrence-of-a-character";
    snippet.log(URL.split('/').slice(0, 5).join('/'));
    
    
    

提交回复
热议问题