Variable Is Not Iterable Javascript Substring Replace