检查值是否是JavaScript中的对象 [英] Check if a value is an object in JavaScript

查看:119
本文介绍了检查值是否是JavaScript中的对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查某个值是否为JavaScript中的对象?

How do you check if a value is an Object in JavaScript?

推荐答案

尝试使用 typeof (var)和/或 var instanceof something

编辑:这个答案给出了关于如何检查变量属性的想法,但它是一个防弹配方(毕竟根本没有配方!)来检查它是否是一个远离它的对象。由于人们倾向于在没有进行任何研究的情况下从这里寻找要复制的东西,我强烈建议他们转向另一个,最受欢迎(并且正确!)的答案。

This answer gives an idea of how to examine variable's properties, but it is not a bulletproof recipe (after all there's no recipe at all!) for checking whether it's an object, far from it. Since people tend to look for something to copy from here without doing any research, I'd highly recommend that they turn to the other, most upvoted (and correct!) answer.

这篇关于检查值是否是JavaScript中的对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆