Checking for Null in an Object
for ( var i=0; i<MyArrayObj.length; 开发者_StackOverflowi++ ) {
}
I am getting an error called, Cannot call MyArrayObj, since its is NULL
Assuming there isn't a logical error with MyArrayObj
being null:
if(MyArrayObj) {
for ( var i=0; i<MyArrayObj.length; i++ ) {
}
}
You can also add this line above your loop just to be sure and avoid having to check at all:
MyArrayObj = MyArrayObj || [];
This will assign empty array into the variable in case it's null or undefined.
Did you declare the MyArrayObj and assigned a correct value to it?
Could you provide the code where you assign the array to a value?
Otherwise check if the array is not null first.
So that means you must not have initialized myArrayObj yet. You have to put something in the array before you can iterate through it.
精彩评论