Variable Is Not Iterable Javascript Substring End