Why is an array of objects considered an object, and not an array? For example:
$.ajax({
url: 'http://api.twitter.com/1/statuses/user_timeline.json',
data: { screen_name: 'mick__romney'},
dataType: 'jsonp',
success: function(data) {
console.dir(data); //Array[20]
alert(typeof data); //Object
}
});
One of the weird behaviour and spec in Javascript is the typeof Array is
Object.You can check if the variable is an array in couple of ways:
But the most reliable way is:
Since you tagged your question with jQuery, you can use jQuery
isArrayfunction: