类型的东西返回对象而不是数组 [英] typeof something return object instead of array

查看:42
本文介绍了类型的东西返回对象而不是数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

x 是一个数组.

我知道了 console.log(x)

[ 'value' ]

但是当我用类似 console.log(typeof x)的类型检查x时,它说这是一个对象.为什么?

but when I check the x with type of like console.log(typeof x) it says it's an Object. Why?

推荐答案

数组是JS中的对象.

如果您需要测试数组变量:

If you need to test a variable for array:

if (x.constructor === Array)
   console.log('its an array');

这篇关于类型的东西返回对象而不是数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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