[javascript] How to return part of string before a certain character?