Published
Edited
Dec 9, 2018
Insert cell
Insert cell
// The official polyfill, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray#Polyfill
function isArrayMdnOfficial(objToCheck) {
return Object.prototype.toString.call(objToCheck) === '[object Array]';
}
Insert cell
// duck-typing approach... could push it to an extreme and check for every Array method
function isArrayLengthAndPushCheck(objToCheck) {
return Boolean(objToCheck) && objToCheck.length != null && typeof objToCheck.push === 'function';
}
Insert cell
// Check the constructor
function isArrayConstructor(objToCheck) {
return Boolean(objToCheck) && objToCheck.constructor === Array;
}
Insert cell
// Use instanceof, doesn't work across windows
function isArrayInstanceOf(objToCheck) {
return objToCheck instanceof Array;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more