Variable Is Not Iterable Javascript Substring Until Character