How do you check if a variable is an array in JavaScript? [duplicate]
https://stackoverflow.com/questions/767486/how-do-you-check-if-a-variable-is-an-array-in-javascript
1137down voteaccepted
|
There are several ways of checking if an variable is an array or not. The best solution is the one you have chosen.
This is the fastest method on Chrome, and most likely all other browsers. All arrays are objects, so checking the constructor property is a fast process for JavaScript engines. If you are having issues with finding out if an objects property is an array, you must first check if the property is there.
Some other ways are:
This method runs about 1/3 the speed as the first example. Still pretty solid, looks cleaner, if you're all about pretty code and not so much on performance. Note that checking for numbers does not work as
This last one is, in my opinion the ugliest, and it is one of the slowest. Running about 1/5 the speed as the first example. Array.prototype, is actually an array. you can read more about it here https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/isArray So yet another update
This guy is the slowest for trying to check for an Array. However, this is a one stop shop for any type you're looking for. However, since you're looking for an array, just use the fastest method above. Also, I ran some test: http://jsperf.com/instanceof-array-vs-array-isarray/33 So have some fun and check it out. Note: @EscapeNetscape has created another test as jsperf.com is down. http://jsben.ch/#/QgYAV I wanted to make sure the original link stay for whenever jsperf comes back online. |
How do you check if a variable is an array in JavaScript? [duplicate]的更多相关文章
- myeclipse使用maven插件进行maven install时报错check $m2_home environment variable and mvn script match
check $m2_home environment variable and mvn script match 分类: maven2015-09-01 18:06 842人阅读 评论(0) 收藏 举 ...
- -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.
一, eclipse中使用maven插件的时候,运行run as maven build的时候报错 -Dmaven.multiModuleProjectDirectory system propery ...
- idea 14运行java工程报错-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.
报错信息:Disconnected from the target VM, address: '127.0.0.1:59770', transport: 'socket' -Dmaven.multiM ...
- 接上一篇博客(解决-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match. )
解决-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variabl ...
- maven 运行tomcatrun -Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match.
解决-Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment varia ...
- Intellij +Maven 报错: Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match.
在intellij使用 Maven Project 测试时,运行test时看到log里的报错信息: -Dmaven.multiModuleProjectDirectory system propert ...
- eclipse+Maven插件报错:-Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable and mvn script match.
问题描述: eclipse indigo+maven3.3.3+jdk1.70 maven插件执行报错:-Dmaven.multiModuleProjectDirectory system prope ...
- -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME environment variable a
eclipse中使用maven插件的时候,运行run as maven build的时候报错 -Dmaven.multiModuleProjectDirectory system propery is ...
- -Dmaven.multiModuleProjectDirectory system property is not set. Check $M2_HOME environment variable and mvn script match.
在执行[maven clean]的时候报错,错误信息如下: -Dmaven.multiModuleProjectDirectory system property is not set. Check ...
随机推荐
- jeecms标签
.@cms_content_list--新闻单页 [@cms_content channelId=' dateFormat='MM-dd' ] [#if tag_list?size>0] < ...
- axios 里面 then 默认写的function里面没有this,改成箭头函数后就可以用this了
,methods:{ loadJson:function(){ //this.jsonTest = "jjj" this.$http.get('http://localhost:3 ...
- 检查bug
用selective_search生成的坐标是(ymin,xmin,ymax,xmax),并且是从1开始的,不是从0 这是cache中的gt数据,明显看到有65535,说明很有可能是0-1变成了655 ...
- python猜年龄游戏升级版
猜年龄游戏升级版 要求:允许用户最多尝试3次,每尝试3次后,如果还没猜对,就问用户是否还想继续玩,如果回答Y,就继续让其猜3次,以此往复,如果回答N,就退出程序,如何猜对了,就直接退出 age = 1 ...
- 漫谈Word2vec之skip-gram模型
https://zhuanlan.zhihu.com/p/30302498 陈运文 复旦大学 计算机应用技术博士 40 人赞同了该文章 [作者] 刘书龙,现任达观数据技术部工程师,兴趣方向主要为自 ...
- Java中的线程安全和非线程安全以及锁的几个知识点
1. 线程安全就是多线程访问时,采用了加锁机制,当一个线程访问该类的某个数据时,进行保护,其他线程不能进行访问直到该线程读取完,其他线程才可使用.不会出现数据不一致或者数据污染. 线程不安全就是不提供 ...
- Linux系统权限
目 录 第1章 权限描述 1 1.1 权限描述 1 1.2 文件权限对应表 1 1.3 三种角色 1 1.4 文件和用户以及组之间的关系 1 第2章 修改权限命令chmo ...
- manjaro xfce 18.0 踩坑记录
manjaro xfce 18.0 踩坑记录 1 简介1.1 Manjaro Linux1.2 开发桌面环境2 自动打开 NumLock3 系统快照3.1 安装timeshift3.2 使用times ...
- Android开发——Accessibility机制实现模拟点击(微信自动抢红包实现)
1. 何为Accessibility机制 许多Android使用者因为各种情况导致他们要以不同的方式与手机交互.对于那些由于视力.听力或其它身体原因导致不能方便使用Android智能手机的用户,And ...
- poj2891 Strange Way to Express Integers poj1006 Biorhythms 同余方程组
怎样求同余方程组?如: \[\begin{cases} x \equiv a_1 \pmod {m_1} \\ x \equiv a_2 \pmod {m_2} \\ \cdots \\ x \equ ...