javascript substring from right to left