Uncaught TypeError: Cannot call method 'push' of undefined
11,852
It's not really easy to tell, but basing on a comments, the object you're calling push
method on is probably undefined
. And this object
should be an array
.
Replace this line:
layer[result['layerId']].push(result);
With following code:
if("undefined" != typeof layer[result['layerId']]) {
layer[result['layerId']].push(result);
}
else {
layer[result['layerId']] = new Array();
layer[result['layerId']].push(result);
}
Let me know if it works.
Author by
SpencerChantler123
Updated on June 04, 2022Comments
-
SpencerChantler123 almost 2 years
I have been stuck at this error for days, can any kind soul decipher this error? The alert shows the correct data that is needed but somehow the push() method just doesn't work.. Thanks in advance!