how can I remove this URL section from this string (representing the URL) using old JavaScript?

后端 未结 4 668
清酒与你
清酒与你 2021-01-29 12:32

I am not so into JavaScript and I have the following problem.

I have a string like this:

https://smart.XXX.it/default.asp/s4

into a var

相关标签:
4条回答
  • 2021-01-29 12:58
    var url = 'https://smart.XXX.it/default.asp/s4';
    var var2 = url.replace('default.asp/', '');
    console.log(var2);
    //Output
    https://smart.XXX.it/s4
    
    0 讨论(0)
  • 2021-01-29 12:58

    You could .split() the url like such:

    let url = 'https://smart.XXX.it/default.asp/s4'.split('/default.asp/').join('/');
    console.log(url);

    0 讨论(0)
  • 2021-01-29 12:59

    You could use String.replace:

    const url = 'https://smart.XXX.it/default.asp/s4'.replace('/default.asp', '');
    
    console.log(url);

    0 讨论(0)
  • 2021-01-29 13:15
    a = 'https://smart.XXX.it/default.asp/s4';
    a = a.split('/');
    a = a.filter((item)=>{
    return item.indexOf('default.asp') === -1;
    });
    a = a.join('/');
    
    0 讨论(0)
提交回复
热议问题