While Loop Through String Javascript Substring Index