Get everything after the dash in a string in javascript

前端 未结 9 2048
故里飘歌
故里飘歌 2020-11-30 22:47

What would be the cleanest way of doing this that would work in both IE and firefox.

My string looks like this: sometext-20202

Now the \'sometext\' and the

9条回答
  •  渐次进展
    2020-11-30 23:14

    How I would do this:

    // function you can use:
    function getSecondPart(str) {
        return str.split('-')[1];
    }
    // use the function:
    alert(getSecondPart("sometext-20202"));
    

提交回复
热议问题