字符串截取最后一个“/“前面或后面的全部字符串

    const http = 'https://www.baidu.com/?tn=40020637_5_oem_dg'
    const str = http.substring(http.lastIndexOf("/")+1)
    console.log(str); //?tn=40020637_5_oem_dg
    const str2 = http.substring(0,http.lastIndexOf("/"))
    console.log(str2); //https://www.baidu.com

 


版权声明:本文为liuzaixi原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。