Everyone else has posted some perfectly reasonable answers. I took a different direction. Without using split, substring, or indexOf. Works great on i.e. and firefox. Probably works on Netscape too.
Just a loop and two ifs.
function getAfterDash(str) { var dashed = false; var result = ""; for (var i = 0, len = str.length; i < len; i++) { if (dashed) { result = result + str[i]; } if (str[i] === '-') { dashed = true; } } return result;};console.log(getAfterDash("adfjkl-o812347"));
My solution is performant and handles edge cases.
The point of the above code was to procrastinate work, please don't actually use it.