Possible Duplicate:
How to detect if a variable is an array
When I need to test if variable is an array (for example input argument in a function that could be object or array) I usually use this piece of code
typeof(myVar) === 'object' && myVar.length !== undefined;
Is this the correct way or is there a more efficient way, considering that even if myVar instanceof Array is faster it should be avoided due to iframe problem?
Array.isArrayis now available with ECMAScript 5, so you can use it with a polyfill for older browsers: