Say I have a function like so:
function foo(bar) {
if (bar > 1) {
return [1,2,3];
} else {
return 1;
}
}
And say I call foo(1)
, how do I know it returns an array or not?
I use this function:
function isArray(obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
}
Is the way that jQuery.isArray is implemented.
Check this article:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With