Java While Loop Through An Array Javascript Function