I would write something to count all types
var obj = { k1: ['a','b'], k2: ['cd','ef'], k3: 0, k4: 1, k5: {a:'b'}, k6: new Date(), k7: "foo" }; function getType(obj) { var type = Object.prototype.toString.call(obj).slice(8, -1); if (type === 'Object') return obj.constructor.name; return type; } function countTypes(obj) { var k, hop = Object.prototype.hasOwnProperty, ret = {}, type; for (k in obj) if (hop.call(obj, k)) { type = getType(obj[k]); if (!ret[type]) ret[type] = 1; else ++ret[type]; } return ret; } var theTypes = countTypes(obj);
Now, if I wanted to know only the number of arrays
var numArrays = theTypes.Array || 0;
source share