I have this code:
var arrayInstSaude = new Array();
$("input[name='uniSaudePrj']:checked").each(function(){
arrayInstSaude[$(this).val()]=$(this).val();
});
For some reason it gives me a messed array. Exemple:
- if I check 1 element value eq 1. It gives me the arrayInstSaude length equal 2.
- if I check 2 elements value eq 2. It gives me the arrayInstSaude length equal 3.
- if I check 3 elements value eq 5. It gives me the arrayInstSaude length equal 6.
- if I check 4 elements value eq 6. It gives me the arrayInstSaude length equal 7.
- if I check 5 elements value eq 7. It gives me the arrayInstSaude length equal 8.
If I do that for 5 elements:
for (var i = 1; i <=arrayInstSaude.length; i++) {
alert(arrayInstSaude[i]);
}
I will have 1,2,undefined,undefined,5,6,7,undefined, while it was expected to have 1,2,5,6,7. Someone know what is going on? Thanks!
array[1], the length is 2 because it hasarray[0]andarray[1].arrayInstSaude[5]it automatically creates 3 & 4, but with no values. It can't just leave them out.