Suppose you have an array like this:
locationHeaders = [];
locationHeaders[1] = "foo";
locationHeaders[3] = "bar";
What's the arrayLen()? It's 2.
However if you loop from 1 to 2, you'll get an error when you try to access the non-existent second element. So presumably you've got a similar issue, not every element in your array is populated. Try dumping it out and see exactly what its contents are.
You might want to consider looping over your array in a different manner.