$ 0 0 Try adding a trim and observe the behavior return ("-" + a.substring(0,a.indexOf("-")).trim());