【问题标题】:how to extract a portion of string from the end in javascript? [duplicate]如何在javascript中从末尾提取一部分字符串? [复制]
【发布时间】:2020-09-28 13:13:44
【问题描述】:

我有这个url https://something.io/room2 我需要提取“room2”或最后一个“/”之后的任何内容,谢谢

【问题讨论】:

    标签: javascript string slice


    【解决方案1】:

    试试这个:

    const str = "https://something.io/room2";
    const splitArr = str.split('/');
    const lastStr = splitArr[splitArr.length - 1];
    console.log(lastStr);

    【讨论】:

    • 请删除问题上的负面标记,我是编程新手
    • 很高兴帮助:)
    猜你喜欢
    • 2017-07-07
    • 1970-01-01
    • 2023-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-20
    • 1970-01-01
    相关资源
    最近更新 更多