In pre-es6 days, there was no straight forward way of determining if a variable contains an array or an object.
typeof arr always gives you
object even though
arr contains an array.
So how did we check?
Well this is kind of a hack, but we need to use the combination of the
Object's prototype method called
Function's prototype method called
As seen below, when you do
Object.prototype.toString.call on an array, it gives exactly this string:
[object Array]. Whereas if you do it on an object, it gives this string:
[object Object]. Always!
Luckily, the TC39 folks found this hack to be cumbersome and adopted a static method on
Array.isArray to find out a given value is indeed an array or not.