这是用于检查isarray的最佳方法 [英] which is the best method used for checking isarray

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

问题描述

我想检查变量是否为数组?

I want to check a variable is it array?

这是获得更好性能的最佳方法。

which is the best method used for this to get better performance.

isArray

instanceof

推荐答案

大家伙(Jquery,下划线)就像这样做这个:

Big guys (Jquery, underscore) do it like this:

  isArray = Array.isArray || function(obj) {
    return Object.prototype.toString.call(obj) == '[object Array]';
  };

这些不是你正在寻找的机器人你真的不喜欢根本不需要这个。不要检查你的变量 - 只要知道它们。

But these are not the droids you're looking for you actually don't need this at all. Don't "check" your variables - just know them.

这篇关于这是用于检查isarray的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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