javascript - Getting an error message when trying to push to an array -


i have following code:

  if (typeof $scope.grid.data == 'undefined') {         $scope.grid.data = [];   }   $scope.grid.data.push(result); 

i put in check undefined still getting error message push saying:

typeerror: cannot call method 'push' of null 

any advice appreciated

i've been fine simple :

if (!$scope.grid.data) {     $scope.grid.data = []; } 

this should catch in both situations (null & undefined).

http://jsfiddle.net/ericjbasti/kxgju/1/

http://jsfiddle.net/ericjbasti/kxgju/2/


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -