While Loop Through Array In Javascript Functions