Swift Loop Through Array Javascript Length Function In R