While Loop Structure Javascript Substring Until Character