var object = {a: 1, b: 2};
console.log('object: has object', _.isObject(object)); //true
console.log('object: has array', _.isArray(object)); //false
console.log('object: has', toString.call(object)); //[object Object]
var object2 = {t: [{a: 1, b: 2}, {c: 3, d: 4}]};
console.log('object2: has object', _.isObject(object)); //true
console.log('object2: has array', _.isArray(object)); //false
console.log('object2: has', toString.call(object2)); //[object Object]
var array = [1, 2];
console.log('array: has object', _.isObject(array)); //true
console.log('array: has array', _.isArray(array)); //true
console.log('array: has', toString.call(array)); //[object Array]
var array2 = [{a: 1, b: 2}, {c: 3, d: 4}];
console.log('array2: has object', _.isObject(array2)); //true
console.log('array2: has array', _.isArray(array2)); //true
console.log('array2: has', toString.call(array2)); //[object Array]
Hi @afranioce! That looks about right to me. Which part would you like to contest?
The type should not be false?
//using jQuery
jQuery.type ([1, 2]) //array
I'm not sure what you mean, but I think you're implying that _.isObject([])
should return false
. This is not the case as arrays are most certainly objects.
I think he was looking for
_.isPlainObject([1,2]) // false
Yes. I should have been more specific. He was looking for a method like isPlainObject. Thanks.
_.isPlainObject
+1 for sure. why not? its so useful!!
+1 why not? is there another way/method in underscore for that?
Most helpful comment
I think he was looking for