IE8下不识别indexOf的问题

news/2024/7/5 6:01:13

1、为Array原型添加indexOf方法(如果学过面向对象,相当于给Array类添加实例方法),方法体如下:

//添加数组IndexOf方法
if (!Array.prototype.indexOf){Array.prototype.indexOf = function(elt /*, from*/){var len = this.length >>> 0;var from = Number(arguments[1]) || 0;from = (from < 0)? Math.ceil(from): Math.floor(from);if (from < 0)from += len;for (; from < len; from++){if (from in this && this[from] === elt)return from;}return -1;};
}

 

2、使用jQuery的inArray方法,注:jQuery版本2.0以上不再支持IE8

var arr = [ 1, "2", false, "aaa" ];
jQuery.inArray("aaa", arr);  
jQuery.inArray(false, arr);  
jQuery.inArray("2", arr);  
jQuery.inArray(1, arr, 2); 

不存在就为-1;


http://lihuaxi.xjx100.cn/news/240534.html

相关文章

配深度学习环境要注意的不多,也就

1. 使用nvcc -V命令查看cuda版本&#xff0c;再在官网选择对应版本的pytorch。(是的不要根据python的版本去选择pytorch指令) 2. 用conda安装pytorch可能一直有cpuonly的玄学问题。(哪怕选择的是CUDA版本的pytorch安装命令)改用pip安装。 3. torchtext不会被顺带安装&#xf…

配置Tomcat和在Eclipse中创建Web工程

配置Tomcat服务器信息&#xff1a;在Tomcat的安装目录下有一个conf目录&#xff0c;里面存放着Tomcat服务器的配置文件&#xff0c;其中最为核心的配置文件是server.xml&#xff0c;在这个文件里我们可以配置服务器的各种参数&#xff0c;例如超时时间、连接数量、端口配置等等…

kvm启动报错

[rootstorage ~]# virsh -c qemu:///system list error: failed to connect to the hypervisor error: Failed to connect socket to /var/run/libvirt/libvirt-sock: No such file or directory原因&#xff1a;libvirt未启动解决方法[rootstorage ~]# libvirtd -d [rootst…

构建node.js基础镜像_在Android上构建Node.js应用程序

构建node.js基础镜像by Aurlien Giraud通过AurlienGiraud 在Android上构建Node.js应用程序-第1部分&#xff1a;Termux&#xff0c;Vim和Node.js (Building a Node.js application on Android - Part 1: Termux, Vim and Node.js) If you are excited about Node.js and own a…

python标准库介绍——23 UserString 模块详解

UserString 模块(2.0 新增) UserString 模块包含两个类, //UserString// 和 //MutableString// . 前者是对标准字符串类型的封装, 后者是一个变种, 允许你修改特定位置的字符(联想下列表就知道了).注意 //MutableString// 并不是效率很好, 许多操作是通过切片和字符串连接实现…

cloud turbine

turbine是聚合服务器发送事件流数据的一个工具&#xff0c;hystrix的监控中&#xff0c;只能监控单个节点&#xff0c;实际生产中都为集群&#xff0c;因此可以通过 turbine来监控集群下hystrix的metrics情况&#xff0c;通过eureka来发现hystrix服务。 1.断路器1 入口类 Sprin…

ux体验网站 英国_?? 用户体验(UX)资源和工具的完整列表??

ux体验网站 英国by Jason Hreha杰森赫雷哈(Jason Hreha) ?? 用户体验(UX)资源和工具的完整列表?? (?? The Complete List of User Experience (UX) Resources & Tools ??) 超过100个链接&#xff0c;可以链接到最好的书籍&#xff0c;课程&#xff0c;新闻通讯和工…

大众点评数据平台架构变迁

2019独角兽企业重金招聘Python工程师标准>>> 最近和其他公司的同学对数据平台的发展题做了一些沟通&#xff0c;发现各自遇到的问题都类似&#xff0c;架构的变迁也有一定的相似性。 以下从数据&架构&应用的角度对2012.07-2014.12期间大众点评数据平台的架构…