Reputation: 103727
I have an array that might be present in my .aspx page, if it is, I want to fire a javascript function.
I tried:
if(someArray)
blah(someArray);
but I get an error when I havent' defined someArray.
Upvotes: 2
Views: 924
Reputation: 12170
var a = [];
var b = new Array();
alert(typeof a === "object" && a instanceof Array);
alert(typeof b === "object" && b instanceof Array);
alert(typeof c === "object" && c instanceof Array);
Upvotes: 0
Reputation: 91742
You should probably be pre-defining the array as null and check to see if it resolves, rather than sometimes available.
Array someArray = null;
// this is where you'll populate or replace someArray
// if you don't, someArray simply remains empty
if (someArray)
{
...
}
Upvotes: 3
Reputation: 488744
if(typeof someArray !== 'undefined') {
blah(someArray);
}
Upvotes: 8