检查变量是否为数组的最佳方法是什么? [英] Best way to check if variable is array?

查看:73
本文介绍了检查变量是否为数组的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了许多可能的解决方案,但都有其缺点,例如:如果它来自不同的框架,或者它是一个自定义对象,包括构造函数中的数组等,但都超过3个月。 lattest提到了ECMAScript第5版附带的Array.isArray([])但不适用于IE7及更低版本。想知道是否有一个确定的解决方案适用于所有人?


P.S.对于我的特定应用程序,我从JSON中获取一些数组并想检查它们是否为数组,然后检查teir length属性以查看它们是否在

I have read lots and lots of possible solutions all with its drawbacks, e.g. if it from a different frame or if it is a custom object including ''array'' in its constructor, etc. but all more than 3 months old. The lattest mentioned Array.isArray([]) that comes with ECMAScript 5th Edition but do not work with IE7 and lower. Wanna know if there is a sure-proof solution for all?

P.S. For my particular application I take some arrays from JSON and want to check that they are arrays and then check teir length property to see if they have data inside

推荐答案

中有数据,因为JSON只支持Object和Array对象,其中一个旧的构造函数检查就足够了
since JSON supports only the Object and Array objects, one of the old constructor checks is sufficient


找到这个页面
http://perfectionkills.com/instanceo...obust-isarray/ br />
结论使用
found this page
http://perfectionkills.com/instanceo...obust-isarray/
which concludes using
展开 | 选择 | Wrap | < /温泉n> 行号


toString()是一种非常非常基本的方法。这绝对不是最近添加的
toString() is a very, very basic method. that’s definitely not a recent addition


这篇关于检查变量是否为数组的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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