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