I have
<div id="exp">
<input type="hidden" name="sum[]" value="1" />
<input type="hidden" name="sum[]" value="2" />
<input type="hidden" name="sum[]" value="3" />
<input type="hidden" name="sum[]" value="4" />
</div>
And I want in jquery get the value of the last element of the array. I've tried:
alert(sum[sum.length-1]);
But shows me 'undefined'. What am I doing wrong?
sum[]can be accessed through a global array variable namedsum. That's not the case. To obtain the last element within a container, you have to query the DOM as jfriend00 demonstrates in his answer.