Check that value is object literal?
up vote
23
down vote
favorite
I have a value and want to know if it's an iteratable object literal, before I iterate it.
How do I do that?
javascript
add a comment |
up vote
23
down vote
favorite
I have a value and want to know if it's an iteratable object literal, before I iterate it.
How do I do that?
javascript
2
Please define "iterable".
– Bergi
Dec 5 '15 at 17:31
add a comment |
up vote
23
down vote
favorite
up vote
23
down vote
favorite
I have a value and want to know if it's an iteratable object literal, before I iterate it.
How do I do that?
javascript
I have a value and want to know if it's an iteratable object literal, before I iterate it.
How do I do that?
javascript
javascript
edited Dec 1 '10 at 6:12
Ivo Wetzel
40.8k1184103
40.8k1184103
asked Dec 1 '10 at 2:48
ajsie
28.5k88244357
28.5k88244357
2
Please define "iterable".
– Bergi
Dec 5 '15 at 17:31
add a comment |
2
Please define "iterable".
– Bergi
Dec 5 '15 at 17:31
2
2
Please define "iterable".
– Bergi
Dec 5 '15 at 17:31
Please define "iterable".
– Bergi
Dec 5 '15 at 17:31
add a comment |
9 Answers
9
active
oldest
votes
up vote
37
down vote
This should do it for you:
if( Object.prototype.toString.call( someObject ) === '[object Object]' ) {
// do your iteration
}
From ECMAScript 5 Section 8.6.2 if you're interested:
The value of the [[Class]] internal property is defined by this specification for every kind of built-in object. The value of the [[Class]] internal property of a host object may be any String value except one of "Arguments", "Array", "Boolean", "Date", "Error", "Function", "JSON", "Math", "Number", "Object", "RegExp", and "String". The value of a [[Class]] internal property is used internally to distinguish different kinds of objects. Note that this specification does not provide any means for a program to access that value except through Object.prototype.toString (see 15.2.4.2).
3
This is no longer guaranteed to work in ES6, as an object can change the value of its Symbol.toStringTag property, which is used to generate Object.prototype.toString's return value. See the note at: people.mozilla.org/~jorendorff/… It looks like the way to check if something's iterable now is to see if it's Symbol.iterator property is defined
– Ethan
Mar 18 '15 at 9:48
Object.prototype.toStringcould be overridden; thus, not safe.
– Frederik Krautwald
May 12 '15 at 21:11
5
If its ever overwritten; that dev should be shot! Any prototypical structure can have its methods overwritten, and in turn would be useless if you could not depend on them.
– Josh Mc
Aug 5 '15 at 2:01
1
for the ppl who still using to this answer be careful :var str; toString.call( str)if the value is undefined or null it will comeback "object" in IE < 9 and some mobiles . checkout first for undefined and null before you apply this condition .
– SUB-HDR
Feb 26 at 21:30
add a comment |
up vote
6
down vote
You could also do something like:
if (someObject.constructor == Object) {
// do your thing
}
you can read more about it here
2
If someObject is null, it doesn't have a constructor and therefore this throws a TypeError. You really want the first answer above.
– chilts
Jun 13 '13 at 3:19
This is far more elegant than the accepted answer for situations where you're trying to distinguish between arrays and objects in js.
– ekillaby
Jul 10 '13 at 18:44
@countfloortiles: yes and no -someObject.constructor = Objectand the test will return true from there on.
– CoDEmanX
Dec 5 '14 at 23:39
@CoDEmanX, I don't understand what you mean.
– ekillaby
Dec 6 '14 at 0:23
@countfloortiles:.constructorcan be overridden, so using it for type checking is not 100% safe.
– CoDEmanX
Dec 6 '14 at 14:27
|
show 2 more comments
up vote
3
down vote
I think a function like this should be native, just like Array.isArray:
Object.isObject = function(obj) {
return obj && obj.constructor === this || false;
};
This one doesn't make function calls nor string comparisons, and doesn't reference global objects (like Object), so it should be quite fast. I don't think this will used in performance intensive tasks though, but whatever.
I'm not totally convinced about the name... maybe something like Object.isLiteral would be better.
It can cause problem with host objects, though, but I don't have a test ready.
the|| falsepart is pretty unnecessary.
– user633183
Jan 28 '14 at 16:21
5
@naomik It's not if you want the function to always return a boolean. Ifobj === nullit'd returnnullinstead. You can always go forreturn obj != null && object.constructor === this;.
– MaxArt
Jan 28 '14 at 21:04
2
The other way isreturn !!(obj && obj.constructor === this)
– Aram Kocharyan
Sep 9 '15 at 3:25
add a comment |
up vote
2
down vote
Say you have some testvar and want to see if it is an object, but not an array or null (these are both of type Object). You can do the following
testVar instanceof Object && !Array.isArray(testVar) && testVar !== null
add a comment |
up vote
0
down vote
Well, you don't need to check everything by yourself or write your own codes, when there are good libraries such as Lodash and Underscore.
In Lodash, you can easily check it by isPlainObject function, e.g.:
_.isPlainObject({'a': 12});
Check this page: https://lodash.com/docs#isPlainObject
Just to be clear, Underscore has no such function - it does have _.isObject but that does not check for a plain object / object literal (e.g. it returns true also for an array)
– JHH
Apr 18 at 7:07
add a comment |
up vote
0
down vote
Bumping old thread, but it's still shows up in searches and people are even referencing it as duplicate for a new similar ones - and still the top-most answers here are far from being correct (sorry people, no offends).
To check if variable is an object the following should be used:
if (typeof variable === 'object') {
// do something
}
Arrays are also objects, so this would be true for an array too.
Moreover - null is a valid object as well, therefore the above will return true on null too.
Personally, when really need to check if an expected variable is 'workable' object I'm always using this boringly repeated formula:
if (variable && typeof variable === `object`) {
// do something
}
Last but not least :) please please please, do yourself a favor and don't use any libraries for such a simple things. Javascript is a fastly evolving language having today much much more than yesterday, so fast that most of the libraries are not even fast enough to fetch up.
Beside it, people who are working on the spec are doing a great job and mostly the native APIs are clean, correct, making perfect sense and coherent with the rest of the language.
add a comment |
up vote
0
down vote
Little gist, not really elegant but efficient
function _isObj( _obj ){
return ( typeof _obj === "object" && JSON.stringify( _obj ).indexOf( "{" ) == 0 );
}
Little example
function _isObj( _obj ){
return ( typeof _obj === "object" && JSON.stringify( _obj ).indexOf( "{" ) == 0 );
}
var p = document.createElement( "p" );
p.textContent = "undefined : " + _isObj( undefined );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "null : " + _isObj( null );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "boolean : " + _isObj( true );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "function : " + _isObj( function(){} );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "array : " + _isObj( );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "string : " + _isObj( "{}" );
document.body.appendChild( p );
document.body.appendChild( p );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "number : " + _isObj( 1 );
document.body.appendChild( p );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "object : " + _isObj( {} );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "another object : " + _isObj( p );
document.body.appendChild( p );hope this help
_isObj(new Buffer(1)) // true
– Mirek Rusin
Dec 6 '17 at 22:02
@Mirek why you test "new Buffer(1)" , scenario ?
– Leonardo Ciaccio
Mar 4 at 15:32
add a comment |
up vote
0
down vote
Strangely, I'm seeing different values for toString() for a subclassed object depending how toString() is being called:
Object.prototype.toString.call(aThing)
"[object Object]"
aThing.toString()
"ZmPopupMenu"
That results in a false positive, so I amended it to prefer the object's toString():
var str = someObject.toString
? someObject.toString()
: Object.prototype.toString.call(someObject);
return str === '[object Object]';
If an objectstoStringproperty is overridden by a function returning a different value,alert, for example, will display that value. However,Object.prototype.toString.call( anObject )will always return the string[object Object]ifanObjectindeed is an object. To haveObject.prototype.toStringreturn something different, theObject’s prototypetoStringmust itself be overridden.
– Frederik Krautwald
May 12 '15 at 21:05
add a comment |
up vote
-2
down vote
This works for me:
function isObject(o) {
try {
return ((typeof o == "object") && (o !== null) && (o.length === undefined));
} catch (err) {
return false;
}
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4320767%2fcheck-that-value-is-object-literal%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
9 Answers
9
active
oldest
votes
9 Answers
9
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
37
down vote
This should do it for you:
if( Object.prototype.toString.call( someObject ) === '[object Object]' ) {
// do your iteration
}
From ECMAScript 5 Section 8.6.2 if you're interested:
The value of the [[Class]] internal property is defined by this specification for every kind of built-in object. The value of the [[Class]] internal property of a host object may be any String value except one of "Arguments", "Array", "Boolean", "Date", "Error", "Function", "JSON", "Math", "Number", "Object", "RegExp", and "String". The value of a [[Class]] internal property is used internally to distinguish different kinds of objects. Note that this specification does not provide any means for a program to access that value except through Object.prototype.toString (see 15.2.4.2).
3
This is no longer guaranteed to work in ES6, as an object can change the value of its Symbol.toStringTag property, which is used to generate Object.prototype.toString's return value. See the note at: people.mozilla.org/~jorendorff/… It looks like the way to check if something's iterable now is to see if it's Symbol.iterator property is defined
– Ethan
Mar 18 '15 at 9:48
Object.prototype.toStringcould be overridden; thus, not safe.
– Frederik Krautwald
May 12 '15 at 21:11
5
If its ever overwritten; that dev should be shot! Any prototypical structure can have its methods overwritten, and in turn would be useless if you could not depend on them.
– Josh Mc
Aug 5 '15 at 2:01
1
for the ppl who still using to this answer be careful :var str; toString.call( str)if the value is undefined or null it will comeback "object" in IE < 9 and some mobiles . checkout first for undefined and null before you apply this condition .
– SUB-HDR
Feb 26 at 21:30
add a comment |
up vote
37
down vote
This should do it for you:
if( Object.prototype.toString.call( someObject ) === '[object Object]' ) {
// do your iteration
}
From ECMAScript 5 Section 8.6.2 if you're interested:
The value of the [[Class]] internal property is defined by this specification for every kind of built-in object. The value of the [[Class]] internal property of a host object may be any String value except one of "Arguments", "Array", "Boolean", "Date", "Error", "Function", "JSON", "Math", "Number", "Object", "RegExp", and "String". The value of a [[Class]] internal property is used internally to distinguish different kinds of objects. Note that this specification does not provide any means for a program to access that value except through Object.prototype.toString (see 15.2.4.2).
3
This is no longer guaranteed to work in ES6, as an object can change the value of its Symbol.toStringTag property, which is used to generate Object.prototype.toString's return value. See the note at: people.mozilla.org/~jorendorff/… It looks like the way to check if something's iterable now is to see if it's Symbol.iterator property is defined
– Ethan
Mar 18 '15 at 9:48
Object.prototype.toStringcould be overridden; thus, not safe.
– Frederik Krautwald
May 12 '15 at 21:11
5
If its ever overwritten; that dev should be shot! Any prototypical structure can have its methods overwritten, and in turn would be useless if you could not depend on them.
– Josh Mc
Aug 5 '15 at 2:01
1
for the ppl who still using to this answer be careful :var str; toString.call( str)if the value is undefined or null it will comeback "object" in IE < 9 and some mobiles . checkout first for undefined and null before you apply this condition .
– SUB-HDR
Feb 26 at 21:30
add a comment |
up vote
37
down vote
up vote
37
down vote
This should do it for you:
if( Object.prototype.toString.call( someObject ) === '[object Object]' ) {
// do your iteration
}
From ECMAScript 5 Section 8.6.2 if you're interested:
The value of the [[Class]] internal property is defined by this specification for every kind of built-in object. The value of the [[Class]] internal property of a host object may be any String value except one of "Arguments", "Array", "Boolean", "Date", "Error", "Function", "JSON", "Math", "Number", "Object", "RegExp", and "String". The value of a [[Class]] internal property is used internally to distinguish different kinds of objects. Note that this specification does not provide any means for a program to access that value except through Object.prototype.toString (see 15.2.4.2).
This should do it for you:
if( Object.prototype.toString.call( someObject ) === '[object Object]' ) {
// do your iteration
}
From ECMAScript 5 Section 8.6.2 if you're interested:
The value of the [[Class]] internal property is defined by this specification for every kind of built-in object. The value of the [[Class]] internal property of a host object may be any String value except one of "Arguments", "Array", "Boolean", "Date", "Error", "Function", "JSON", "Math", "Number", "Object", "RegExp", and "String". The value of a [[Class]] internal property is used internally to distinguish different kinds of objects. Note that this specification does not provide any means for a program to access that value except through Object.prototype.toString (see 15.2.4.2).
answered Dec 1 '10 at 2:53
user113716
258k55399416
258k55399416
3
This is no longer guaranteed to work in ES6, as an object can change the value of its Symbol.toStringTag property, which is used to generate Object.prototype.toString's return value. See the note at: people.mozilla.org/~jorendorff/… It looks like the way to check if something's iterable now is to see if it's Symbol.iterator property is defined
– Ethan
Mar 18 '15 at 9:48
Object.prototype.toStringcould be overridden; thus, not safe.
– Frederik Krautwald
May 12 '15 at 21:11
5
If its ever overwritten; that dev should be shot! Any prototypical structure can have its methods overwritten, and in turn would be useless if you could not depend on them.
– Josh Mc
Aug 5 '15 at 2:01
1
for the ppl who still using to this answer be careful :var str; toString.call( str)if the value is undefined or null it will comeback "object" in IE < 9 and some mobiles . checkout first for undefined and null before you apply this condition .
– SUB-HDR
Feb 26 at 21:30
add a comment |
3
This is no longer guaranteed to work in ES6, as an object can change the value of its Symbol.toStringTag property, which is used to generate Object.prototype.toString's return value. See the note at: people.mozilla.org/~jorendorff/… It looks like the way to check if something's iterable now is to see if it's Symbol.iterator property is defined
– Ethan
Mar 18 '15 at 9:48
Object.prototype.toStringcould be overridden; thus, not safe.
– Frederik Krautwald
May 12 '15 at 21:11
5
If its ever overwritten; that dev should be shot! Any prototypical structure can have its methods overwritten, and in turn would be useless if you could not depend on them.
– Josh Mc
Aug 5 '15 at 2:01
1
for the ppl who still using to this answer be careful :var str; toString.call( str)if the value is undefined or null it will comeback "object" in IE < 9 and some mobiles . checkout first for undefined and null before you apply this condition .
– SUB-HDR
Feb 26 at 21:30
3
3
This is no longer guaranteed to work in ES6, as an object can change the value of its Symbol.toStringTag property, which is used to generate Object.prototype.toString's return value. See the note at: people.mozilla.org/~jorendorff/… It looks like the way to check if something's iterable now is to see if it's Symbol.iterator property is defined
– Ethan
Mar 18 '15 at 9:48
This is no longer guaranteed to work in ES6, as an object can change the value of its Symbol.toStringTag property, which is used to generate Object.prototype.toString's return value. See the note at: people.mozilla.org/~jorendorff/… It looks like the way to check if something's iterable now is to see if it's Symbol.iterator property is defined
– Ethan
Mar 18 '15 at 9:48
Object.prototype.toString could be overridden; thus, not safe.– Frederik Krautwald
May 12 '15 at 21:11
Object.prototype.toString could be overridden; thus, not safe.– Frederik Krautwald
May 12 '15 at 21:11
5
5
If its ever overwritten; that dev should be shot! Any prototypical structure can have its methods overwritten, and in turn would be useless if you could not depend on them.
– Josh Mc
Aug 5 '15 at 2:01
If its ever overwritten; that dev should be shot! Any prototypical structure can have its methods overwritten, and in turn would be useless if you could not depend on them.
– Josh Mc
Aug 5 '15 at 2:01
1
1
for the ppl who still using to this answer be careful :
var str; toString.call( str) if the value is undefined or null it will comeback "object" in IE < 9 and some mobiles . checkout first for undefined and null before you apply this condition .– SUB-HDR
Feb 26 at 21:30
for the ppl who still using to this answer be careful :
var str; toString.call( str) if the value is undefined or null it will comeback "object" in IE < 9 and some mobiles . checkout first for undefined and null before you apply this condition .– SUB-HDR
Feb 26 at 21:30
add a comment |
up vote
6
down vote
You could also do something like:
if (someObject.constructor == Object) {
// do your thing
}
you can read more about it here
2
If someObject is null, it doesn't have a constructor and therefore this throws a TypeError. You really want the first answer above.
– chilts
Jun 13 '13 at 3:19
This is far more elegant than the accepted answer for situations where you're trying to distinguish between arrays and objects in js.
– ekillaby
Jul 10 '13 at 18:44
@countfloortiles: yes and no -someObject.constructor = Objectand the test will return true from there on.
– CoDEmanX
Dec 5 '14 at 23:39
@CoDEmanX, I don't understand what you mean.
– ekillaby
Dec 6 '14 at 0:23
@countfloortiles:.constructorcan be overridden, so using it for type checking is not 100% safe.
– CoDEmanX
Dec 6 '14 at 14:27
|
show 2 more comments
up vote
6
down vote
You could also do something like:
if (someObject.constructor == Object) {
// do your thing
}
you can read more about it here
2
If someObject is null, it doesn't have a constructor and therefore this throws a TypeError. You really want the first answer above.
– chilts
Jun 13 '13 at 3:19
This is far more elegant than the accepted answer for situations where you're trying to distinguish between arrays and objects in js.
– ekillaby
Jul 10 '13 at 18:44
@countfloortiles: yes and no -someObject.constructor = Objectand the test will return true from there on.
– CoDEmanX
Dec 5 '14 at 23:39
@CoDEmanX, I don't understand what you mean.
– ekillaby
Dec 6 '14 at 0:23
@countfloortiles:.constructorcan be overridden, so using it for type checking is not 100% safe.
– CoDEmanX
Dec 6 '14 at 14:27
|
show 2 more comments
up vote
6
down vote
up vote
6
down vote
You could also do something like:
if (someObject.constructor == Object) {
// do your thing
}
you can read more about it here
You could also do something like:
if (someObject.constructor == Object) {
// do your thing
}
you can read more about it here
answered Dec 1 '10 at 3:27
dcestari
40437
40437
2
If someObject is null, it doesn't have a constructor and therefore this throws a TypeError. You really want the first answer above.
– chilts
Jun 13 '13 at 3:19
This is far more elegant than the accepted answer for situations where you're trying to distinguish between arrays and objects in js.
– ekillaby
Jul 10 '13 at 18:44
@countfloortiles: yes and no -someObject.constructor = Objectand the test will return true from there on.
– CoDEmanX
Dec 5 '14 at 23:39
@CoDEmanX, I don't understand what you mean.
– ekillaby
Dec 6 '14 at 0:23
@countfloortiles:.constructorcan be overridden, so using it for type checking is not 100% safe.
– CoDEmanX
Dec 6 '14 at 14:27
|
show 2 more comments
2
If someObject is null, it doesn't have a constructor and therefore this throws a TypeError. You really want the first answer above.
– chilts
Jun 13 '13 at 3:19
This is far more elegant than the accepted answer for situations where you're trying to distinguish between arrays and objects in js.
– ekillaby
Jul 10 '13 at 18:44
@countfloortiles: yes and no -someObject.constructor = Objectand the test will return true from there on.
– CoDEmanX
Dec 5 '14 at 23:39
@CoDEmanX, I don't understand what you mean.
– ekillaby
Dec 6 '14 at 0:23
@countfloortiles:.constructorcan be overridden, so using it for type checking is not 100% safe.
– CoDEmanX
Dec 6 '14 at 14:27
2
2
If someObject is null, it doesn't have a constructor and therefore this throws a TypeError. You really want the first answer above.
– chilts
Jun 13 '13 at 3:19
If someObject is null, it doesn't have a constructor and therefore this throws a TypeError. You really want the first answer above.
– chilts
Jun 13 '13 at 3:19
This is far more elegant than the accepted answer for situations where you're trying to distinguish between arrays and objects in js.
– ekillaby
Jul 10 '13 at 18:44
This is far more elegant than the accepted answer for situations where you're trying to distinguish between arrays and objects in js.
– ekillaby
Jul 10 '13 at 18:44
@countfloortiles: yes and no -
someObject.constructor = Object and the test will return true from there on.– CoDEmanX
Dec 5 '14 at 23:39
@countfloortiles: yes and no -
someObject.constructor = Object and the test will return true from there on.– CoDEmanX
Dec 5 '14 at 23:39
@CoDEmanX, I don't understand what you mean.
– ekillaby
Dec 6 '14 at 0:23
@CoDEmanX, I don't understand what you mean.
– ekillaby
Dec 6 '14 at 0:23
@countfloortiles:
.constructor can be overridden, so using it for type checking is not 100% safe.– CoDEmanX
Dec 6 '14 at 14:27
@countfloortiles:
.constructor can be overridden, so using it for type checking is not 100% safe.– CoDEmanX
Dec 6 '14 at 14:27
|
show 2 more comments
up vote
3
down vote
I think a function like this should be native, just like Array.isArray:
Object.isObject = function(obj) {
return obj && obj.constructor === this || false;
};
This one doesn't make function calls nor string comparisons, and doesn't reference global objects (like Object), so it should be quite fast. I don't think this will used in performance intensive tasks though, but whatever.
I'm not totally convinced about the name... maybe something like Object.isLiteral would be better.
It can cause problem with host objects, though, but I don't have a test ready.
the|| falsepart is pretty unnecessary.
– user633183
Jan 28 '14 at 16:21
5
@naomik It's not if you want the function to always return a boolean. Ifobj === nullit'd returnnullinstead. You can always go forreturn obj != null && object.constructor === this;.
– MaxArt
Jan 28 '14 at 21:04
2
The other way isreturn !!(obj && obj.constructor === this)
– Aram Kocharyan
Sep 9 '15 at 3:25
add a comment |
up vote
3
down vote
I think a function like this should be native, just like Array.isArray:
Object.isObject = function(obj) {
return obj && obj.constructor === this || false;
};
This one doesn't make function calls nor string comparisons, and doesn't reference global objects (like Object), so it should be quite fast. I don't think this will used in performance intensive tasks though, but whatever.
I'm not totally convinced about the name... maybe something like Object.isLiteral would be better.
It can cause problem with host objects, though, but I don't have a test ready.
the|| falsepart is pretty unnecessary.
– user633183
Jan 28 '14 at 16:21
5
@naomik It's not if you want the function to always return a boolean. Ifobj === nullit'd returnnullinstead. You can always go forreturn obj != null && object.constructor === this;.
– MaxArt
Jan 28 '14 at 21:04
2
The other way isreturn !!(obj && obj.constructor === this)
– Aram Kocharyan
Sep 9 '15 at 3:25
add a comment |
up vote
3
down vote
up vote
3
down vote
I think a function like this should be native, just like Array.isArray:
Object.isObject = function(obj) {
return obj && obj.constructor === this || false;
};
This one doesn't make function calls nor string comparisons, and doesn't reference global objects (like Object), so it should be quite fast. I don't think this will used in performance intensive tasks though, but whatever.
I'm not totally convinced about the name... maybe something like Object.isLiteral would be better.
It can cause problem with host objects, though, but I don't have a test ready.
I think a function like this should be native, just like Array.isArray:
Object.isObject = function(obj) {
return obj && obj.constructor === this || false;
};
This one doesn't make function calls nor string comparisons, and doesn't reference global objects (like Object), so it should be quite fast. I don't think this will used in performance intensive tasks though, but whatever.
I'm not totally convinced about the name... maybe something like Object.isLiteral would be better.
It can cause problem with host objects, though, but I don't have a test ready.
answered Nov 28 '13 at 10:07
MaxArt
15.5k85570
15.5k85570
the|| falsepart is pretty unnecessary.
– user633183
Jan 28 '14 at 16:21
5
@naomik It's not if you want the function to always return a boolean. Ifobj === nullit'd returnnullinstead. You can always go forreturn obj != null && object.constructor === this;.
– MaxArt
Jan 28 '14 at 21:04
2
The other way isreturn !!(obj && obj.constructor === this)
– Aram Kocharyan
Sep 9 '15 at 3:25
add a comment |
the|| falsepart is pretty unnecessary.
– user633183
Jan 28 '14 at 16:21
5
@naomik It's not if you want the function to always return a boolean. Ifobj === nullit'd returnnullinstead. You can always go forreturn obj != null && object.constructor === this;.
– MaxArt
Jan 28 '14 at 21:04
2
The other way isreturn !!(obj && obj.constructor === this)
– Aram Kocharyan
Sep 9 '15 at 3:25
the
|| false part is pretty unnecessary.– user633183
Jan 28 '14 at 16:21
the
|| false part is pretty unnecessary.– user633183
Jan 28 '14 at 16:21
5
5
@naomik It's not if you want the function to always return a boolean. If
obj === null it'd return null instead. You can always go for return obj != null && object.constructor === this;.– MaxArt
Jan 28 '14 at 21:04
@naomik It's not if you want the function to always return a boolean. If
obj === null it'd return null instead. You can always go for return obj != null && object.constructor === this;.– MaxArt
Jan 28 '14 at 21:04
2
2
The other way is
return !!(obj && obj.constructor === this)– Aram Kocharyan
Sep 9 '15 at 3:25
The other way is
return !!(obj && obj.constructor === this)– Aram Kocharyan
Sep 9 '15 at 3:25
add a comment |
up vote
2
down vote
Say you have some testvar and want to see if it is an object, but not an array or null (these are both of type Object). You can do the following
testVar instanceof Object && !Array.isArray(testVar) && testVar !== null
add a comment |
up vote
2
down vote
Say you have some testvar and want to see if it is an object, but not an array or null (these are both of type Object). You can do the following
testVar instanceof Object && !Array.isArray(testVar) && testVar !== null
add a comment |
up vote
2
down vote
up vote
2
down vote
Say you have some testvar and want to see if it is an object, but not an array or null (these are both of type Object). You can do the following
testVar instanceof Object && !Array.isArray(testVar) && testVar !== null
Say you have some testvar and want to see if it is an object, but not an array or null (these are both of type Object). You can do the following
testVar instanceof Object && !Array.isArray(testVar) && testVar !== null
answered Jun 14 '17 at 21:14
Mark
2,49811120
2,49811120
add a comment |
add a comment |
up vote
0
down vote
Well, you don't need to check everything by yourself or write your own codes, when there are good libraries such as Lodash and Underscore.
In Lodash, you can easily check it by isPlainObject function, e.g.:
_.isPlainObject({'a': 12});
Check this page: https://lodash.com/docs#isPlainObject
Just to be clear, Underscore has no such function - it does have _.isObject but that does not check for a plain object / object literal (e.g. it returns true also for an array)
– JHH
Apr 18 at 7:07
add a comment |
up vote
0
down vote
Well, you don't need to check everything by yourself or write your own codes, when there are good libraries such as Lodash and Underscore.
In Lodash, you can easily check it by isPlainObject function, e.g.:
_.isPlainObject({'a': 12});
Check this page: https://lodash.com/docs#isPlainObject
Just to be clear, Underscore has no such function - it does have _.isObject but that does not check for a plain object / object literal (e.g. it returns true also for an array)
– JHH
Apr 18 at 7:07
add a comment |
up vote
0
down vote
up vote
0
down vote
Well, you don't need to check everything by yourself or write your own codes, when there are good libraries such as Lodash and Underscore.
In Lodash, you can easily check it by isPlainObject function, e.g.:
_.isPlainObject({'a': 12});
Check this page: https://lodash.com/docs#isPlainObject
Well, you don't need to check everything by yourself or write your own codes, when there are good libraries such as Lodash and Underscore.
In Lodash, you can easily check it by isPlainObject function, e.g.:
_.isPlainObject({'a': 12});
Check this page: https://lodash.com/docs#isPlainObject
answered Feb 25 '16 at 18:13
Ehsan
796616
796616
Just to be clear, Underscore has no such function - it does have _.isObject but that does not check for a plain object / object literal (e.g. it returns true also for an array)
– JHH
Apr 18 at 7:07
add a comment |
Just to be clear, Underscore has no such function - it does have _.isObject but that does not check for a plain object / object literal (e.g. it returns true also for an array)
– JHH
Apr 18 at 7:07
Just to be clear, Underscore has no such function - it does have _.isObject but that does not check for a plain object / object literal (e.g. it returns true also for an array)
– JHH
Apr 18 at 7:07
Just to be clear, Underscore has no such function - it does have _.isObject but that does not check for a plain object / object literal (e.g. it returns true also for an array)
– JHH
Apr 18 at 7:07
add a comment |
up vote
0
down vote
Bumping old thread, but it's still shows up in searches and people are even referencing it as duplicate for a new similar ones - and still the top-most answers here are far from being correct (sorry people, no offends).
To check if variable is an object the following should be used:
if (typeof variable === 'object') {
// do something
}
Arrays are also objects, so this would be true for an array too.
Moreover - null is a valid object as well, therefore the above will return true on null too.
Personally, when really need to check if an expected variable is 'workable' object I'm always using this boringly repeated formula:
if (variable && typeof variable === `object`) {
// do something
}
Last but not least :) please please please, do yourself a favor and don't use any libraries for such a simple things. Javascript is a fastly evolving language having today much much more than yesterday, so fast that most of the libraries are not even fast enough to fetch up.
Beside it, people who are working on the spec are doing a great job and mostly the native APIs are clean, correct, making perfect sense and coherent with the rest of the language.
add a comment |
up vote
0
down vote
Bumping old thread, but it's still shows up in searches and people are even referencing it as duplicate for a new similar ones - and still the top-most answers here are far from being correct (sorry people, no offends).
To check if variable is an object the following should be used:
if (typeof variable === 'object') {
// do something
}
Arrays are also objects, so this would be true for an array too.
Moreover - null is a valid object as well, therefore the above will return true on null too.
Personally, when really need to check if an expected variable is 'workable' object I'm always using this boringly repeated formula:
if (variable && typeof variable === `object`) {
// do something
}
Last but not least :) please please please, do yourself a favor and don't use any libraries for such a simple things. Javascript is a fastly evolving language having today much much more than yesterday, so fast that most of the libraries are not even fast enough to fetch up.
Beside it, people who are working on the spec are doing a great job and mostly the native APIs are clean, correct, making perfect sense and coherent with the rest of the language.
add a comment |
up vote
0
down vote
up vote
0
down vote
Bumping old thread, but it's still shows up in searches and people are even referencing it as duplicate for a new similar ones - and still the top-most answers here are far from being correct (sorry people, no offends).
To check if variable is an object the following should be used:
if (typeof variable === 'object') {
// do something
}
Arrays are also objects, so this would be true for an array too.
Moreover - null is a valid object as well, therefore the above will return true on null too.
Personally, when really need to check if an expected variable is 'workable' object I'm always using this boringly repeated formula:
if (variable && typeof variable === `object`) {
// do something
}
Last but not least :) please please please, do yourself a favor and don't use any libraries for such a simple things. Javascript is a fastly evolving language having today much much more than yesterday, so fast that most of the libraries are not even fast enough to fetch up.
Beside it, people who are working on the spec are doing a great job and mostly the native APIs are clean, correct, making perfect sense and coherent with the rest of the language.
Bumping old thread, but it's still shows up in searches and people are even referencing it as duplicate for a new similar ones - and still the top-most answers here are far from being correct (sorry people, no offends).
To check if variable is an object the following should be used:
if (typeof variable === 'object') {
// do something
}
Arrays are also objects, so this would be true for an array too.
Moreover - null is a valid object as well, therefore the above will return true on null too.
Personally, when really need to check if an expected variable is 'workable' object I'm always using this boringly repeated formula:
if (variable && typeof variable === `object`) {
// do something
}
Last but not least :) please please please, do yourself a favor and don't use any libraries for such a simple things. Javascript is a fastly evolving language having today much much more than yesterday, so fast that most of the libraries are not even fast enough to fetch up.
Beside it, people who are working on the spec are doing a great job and mostly the native APIs are clean, correct, making perfect sense and coherent with the rest of the language.
answered Apr 7 '17 at 6:33
GullerYA
276310
276310
add a comment |
add a comment |
up vote
0
down vote
Little gist, not really elegant but efficient
function _isObj( _obj ){
return ( typeof _obj === "object" && JSON.stringify( _obj ).indexOf( "{" ) == 0 );
}
Little example
function _isObj( _obj ){
return ( typeof _obj === "object" && JSON.stringify( _obj ).indexOf( "{" ) == 0 );
}
var p = document.createElement( "p" );
p.textContent = "undefined : " + _isObj( undefined );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "null : " + _isObj( null );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "boolean : " + _isObj( true );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "function : " + _isObj( function(){} );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "array : " + _isObj( );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "string : " + _isObj( "{}" );
document.body.appendChild( p );
document.body.appendChild( p );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "number : " + _isObj( 1 );
document.body.appendChild( p );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "object : " + _isObj( {} );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "another object : " + _isObj( p );
document.body.appendChild( p );hope this help
_isObj(new Buffer(1)) // true
– Mirek Rusin
Dec 6 '17 at 22:02
@Mirek why you test "new Buffer(1)" , scenario ?
– Leonardo Ciaccio
Mar 4 at 15:32
add a comment |
up vote
0
down vote
Little gist, not really elegant but efficient
function _isObj( _obj ){
return ( typeof _obj === "object" && JSON.stringify( _obj ).indexOf( "{" ) == 0 );
}
Little example
function _isObj( _obj ){
return ( typeof _obj === "object" && JSON.stringify( _obj ).indexOf( "{" ) == 0 );
}
var p = document.createElement( "p" );
p.textContent = "undefined : " + _isObj( undefined );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "null : " + _isObj( null );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "boolean : " + _isObj( true );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "function : " + _isObj( function(){} );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "array : " + _isObj( );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "string : " + _isObj( "{}" );
document.body.appendChild( p );
document.body.appendChild( p );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "number : " + _isObj( 1 );
document.body.appendChild( p );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "object : " + _isObj( {} );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "another object : " + _isObj( p );
document.body.appendChild( p );hope this help
_isObj(new Buffer(1)) // true
– Mirek Rusin
Dec 6 '17 at 22:02
@Mirek why you test "new Buffer(1)" , scenario ?
– Leonardo Ciaccio
Mar 4 at 15:32
add a comment |
up vote
0
down vote
up vote
0
down vote
Little gist, not really elegant but efficient
function _isObj( _obj ){
return ( typeof _obj === "object" && JSON.stringify( _obj ).indexOf( "{" ) == 0 );
}
Little example
function _isObj( _obj ){
return ( typeof _obj === "object" && JSON.stringify( _obj ).indexOf( "{" ) == 0 );
}
var p = document.createElement( "p" );
p.textContent = "undefined : " + _isObj( undefined );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "null : " + _isObj( null );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "boolean : " + _isObj( true );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "function : " + _isObj( function(){} );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "array : " + _isObj( );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "string : " + _isObj( "{}" );
document.body.appendChild( p );
document.body.appendChild( p );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "number : " + _isObj( 1 );
document.body.appendChild( p );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "object : " + _isObj( {} );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "another object : " + _isObj( p );
document.body.appendChild( p );hope this help
Little gist, not really elegant but efficient
function _isObj( _obj ){
return ( typeof _obj === "object" && JSON.stringify( _obj ).indexOf( "{" ) == 0 );
}
Little example
function _isObj( _obj ){
return ( typeof _obj === "object" && JSON.stringify( _obj ).indexOf( "{" ) == 0 );
}
var p = document.createElement( "p" );
p.textContent = "undefined : " + _isObj( undefined );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "null : " + _isObj( null );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "boolean : " + _isObj( true );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "function : " + _isObj( function(){} );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "array : " + _isObj( );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "string : " + _isObj( "{}" );
document.body.appendChild( p );
document.body.appendChild( p );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "number : " + _isObj( 1 );
document.body.appendChild( p );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "object : " + _isObj( {} );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "another object : " + _isObj( p );
document.body.appendChild( p );hope this help
function _isObj( _obj ){
return ( typeof _obj === "object" && JSON.stringify( _obj ).indexOf( "{" ) == 0 );
}
var p = document.createElement( "p" );
p.textContent = "undefined : " + _isObj( undefined );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "null : " + _isObj( null );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "boolean : " + _isObj( true );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "function : " + _isObj( function(){} );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "array : " + _isObj( );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "string : " + _isObj( "{}" );
document.body.appendChild( p );
document.body.appendChild( p );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "number : " + _isObj( 1 );
document.body.appendChild( p );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "object : " + _isObj( {} );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "another object : " + _isObj( p );
document.body.appendChild( p );function _isObj( _obj ){
return ( typeof _obj === "object" && JSON.stringify( _obj ).indexOf( "{" ) == 0 );
}
var p = document.createElement( "p" );
p.textContent = "undefined : " + _isObj( undefined );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "null : " + _isObj( null );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "boolean : " + _isObj( true );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "function : " + _isObj( function(){} );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "array : " + _isObj( );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "string : " + _isObj( "{}" );
document.body.appendChild( p );
document.body.appendChild( p );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "number : " + _isObj( 1 );
document.body.appendChild( p );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "object : " + _isObj( {} );
document.body.appendChild( p );
p = document.createElement( "p" );
p.textContent = "another object : " + _isObj( p );
document.body.appendChild( p );answered Sep 15 '17 at 7:35
Leonardo Ciaccio
723711
723711
_isObj(new Buffer(1)) // true
– Mirek Rusin
Dec 6 '17 at 22:02
@Mirek why you test "new Buffer(1)" , scenario ?
– Leonardo Ciaccio
Mar 4 at 15:32
add a comment |
_isObj(new Buffer(1)) // true
– Mirek Rusin
Dec 6 '17 at 22:02
@Mirek why you test "new Buffer(1)" , scenario ?
– Leonardo Ciaccio
Mar 4 at 15:32
_isObj(new Buffer(1)) // true– Mirek Rusin
Dec 6 '17 at 22:02
_isObj(new Buffer(1)) // true– Mirek Rusin
Dec 6 '17 at 22:02
@Mirek why you test "new Buffer(1)" , scenario ?
– Leonardo Ciaccio
Mar 4 at 15:32
@Mirek why you test "new Buffer(1)" , scenario ?
– Leonardo Ciaccio
Mar 4 at 15:32
add a comment |
up vote
0
down vote
Strangely, I'm seeing different values for toString() for a subclassed object depending how toString() is being called:
Object.prototype.toString.call(aThing)
"[object Object]"
aThing.toString()
"ZmPopupMenu"
That results in a false positive, so I amended it to prefer the object's toString():
var str = someObject.toString
? someObject.toString()
: Object.prototype.toString.call(someObject);
return str === '[object Object]';
If an objectstoStringproperty is overridden by a function returning a different value,alert, for example, will display that value. However,Object.prototype.toString.call( anObject )will always return the string[object Object]ifanObjectindeed is an object. To haveObject.prototype.toStringreturn something different, theObject’s prototypetoStringmust itself be overridden.
– Frederik Krautwald
May 12 '15 at 21:05
add a comment |
up vote
0
down vote
Strangely, I'm seeing different values for toString() for a subclassed object depending how toString() is being called:
Object.prototype.toString.call(aThing)
"[object Object]"
aThing.toString()
"ZmPopupMenu"
That results in a false positive, so I amended it to prefer the object's toString():
var str = someObject.toString
? someObject.toString()
: Object.prototype.toString.call(someObject);
return str === '[object Object]';
If an objectstoStringproperty is overridden by a function returning a different value,alert, for example, will display that value. However,Object.prototype.toString.call( anObject )will always return the string[object Object]ifanObjectindeed is an object. To haveObject.prototype.toStringreturn something different, theObject’s prototypetoStringmust itself be overridden.
– Frederik Krautwald
May 12 '15 at 21:05
add a comment |
up vote
0
down vote
up vote
0
down vote
Strangely, I'm seeing different values for toString() for a subclassed object depending how toString() is being called:
Object.prototype.toString.call(aThing)
"[object Object]"
aThing.toString()
"ZmPopupMenu"
That results in a false positive, so I amended it to prefer the object's toString():
var str = someObject.toString
? someObject.toString()
: Object.prototype.toString.call(someObject);
return str === '[object Object]';
Strangely, I'm seeing different values for toString() for a subclassed object depending how toString() is being called:
Object.prototype.toString.call(aThing)
"[object Object]"
aThing.toString()
"ZmPopupMenu"
That results in a false positive, so I amended it to prefer the object's toString():
var str = someObject.toString
? someObject.toString()
: Object.prototype.toString.call(someObject);
return str === '[object Object]';
edited Aug 16 at 16:54
Mike Samuel
92.3k23169213
92.3k23169213
answered Feb 3 '15 at 19:16
Conrad Damon
49153
49153
If an objectstoStringproperty is overridden by a function returning a different value,alert, for example, will display that value. However,Object.prototype.toString.call( anObject )will always return the string[object Object]ifanObjectindeed is an object. To haveObject.prototype.toStringreturn something different, theObject’s prototypetoStringmust itself be overridden.
– Frederik Krautwald
May 12 '15 at 21:05
add a comment |
If an objectstoStringproperty is overridden by a function returning a different value,alert, for example, will display that value. However,Object.prototype.toString.call( anObject )will always return the string[object Object]ifanObjectindeed is an object. To haveObject.prototype.toStringreturn something different, theObject’s prototypetoStringmust itself be overridden.
– Frederik Krautwald
May 12 '15 at 21:05
If an objects
toString property is overridden by a function returning a different value, alert, for example, will display that value. However, Object.prototype.toString.call( anObject ) will always return the string [object Object] if anObject indeed is an object. To have Object.prototype.toString return something different, the Object’s prototype toString must itself be overridden.– Frederik Krautwald
May 12 '15 at 21:05
If an objects
toString property is overridden by a function returning a different value, alert, for example, will display that value. However, Object.prototype.toString.call( anObject ) will always return the string [object Object] if anObject indeed is an object. To have Object.prototype.toString return something different, the Object’s prototype toString must itself be overridden.– Frederik Krautwald
May 12 '15 at 21:05
add a comment |
up vote
-2
down vote
This works for me:
function isObject(o) {
try {
return ((typeof o == "object") && (o !== null) && (o.length === undefined));
} catch (err) {
return false;
}
}
add a comment |
up vote
-2
down vote
This works for me:
function isObject(o) {
try {
return ((typeof o == "object") && (o !== null) && (o.length === undefined));
} catch (err) {
return false;
}
}
add a comment |
up vote
-2
down vote
up vote
-2
down vote
This works for me:
function isObject(o) {
try {
return ((typeof o == "object") && (o !== null) && (o.length === undefined));
} catch (err) {
return false;
}
}
This works for me:
function isObject(o) {
try {
return ((typeof o == "object") && (o !== null) && (o.length === undefined));
} catch (err) {
return false;
}
}
answered Jun 17 '13 at 2:00
NeonMonk
223
223
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f4320767%2fcheck-that-value-is-object-literal%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
Please define "iterable".
– Bergi
Dec 5 '15 at 17:31