I keep getting Uncaught TypeError: Cannot set property '0' of undefined
, but I can't for my life figure out what is wrong!
var anchor = [];
getAnchors();
function getAnchors() {
$('.anchor').each(function(i) {
anchor[i] = $(this).offset().left;
});
}
So what is wrong with this code snippet?
I have declared anchor
as an array.
I've been checking for silly typos for an hour now.
The error lies in i
. But what is the error?