javascript,是否有像isArray这样的isObject函数? [英] javascript, is there an isObject function like isArray?

查看:153
本文介绍了javascript,是否有像isArray这样的isObject函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

检查该值是否为对象文字?

I我正在使用可以是null,0或json对象的输出。有了这个,我需要想出一种方法来确定输出是否确实是一个真实的对象。但我找不到任何能给我一个明确答案的答案,如果javascript功能中有类似的东西。如果没有,否则我可以检测到这是否是一个对象?

I am working with an output that can be either null, 0, or a json object. And with that I need to come up with a means of determining if that output is indeed a real object. But I can't find anything that gives me a definitive answer as to if there is something like that in the javascript functionality or not. If there isn't is there a means otherwise that I can detect if this is an object?

推荐答案

你可以使用 typeof 运算符。

You can use typeof operator.

if( (typeof A === "object") && (A !== null) )
{
    alert("A is object");
}

请注意,因为 typeof new Number(1)= =='object' typeof Number(1)==='number'; 应避免使用第一种语法。

Note that because typeof new Number(1) === 'object' while typeof Number(1) === 'number'; the first syntax should be avoided.

这篇关于javascript,是否有像isArray这样的isObject函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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