Reputation: 7631
for ( var i=0; i<MyArrayObj.length; i++ ) {
}
I am getting an error called, Cannot call MyArrayObj, since its is NULL
Upvotes: 0
Views: 144
Reputation: 472
So that means you must not have initialized myArrayObj yet. You have to put something in the array before you can iterate through it.
Upvotes: 0
Reputation: 66389
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.
Upvotes: 3
Reputation: 5612
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.
Upvotes: 1
Reputation: 36456
Assuming there isn't a logical error with MyArrayObj
being null:
if(MyArrayObj) {
for ( var i=0; i<MyArrayObj.length; i++ ) {
}
}
Upvotes: 11