While Loop Structure Javascript Foreach Element