While Loop Through String Javascript Substring