Home > Web Front-end > JS Tutorial > body text

jQuery判断数组是否包含了指定的元素_jquery

WBOY
Release: 2016-05-16 16:10:20
Original
1930 people have browsed it

要判断数组中是否包含某个元素,从原理来来说,就是遍历整个数组,然后判断是否相等,

复制代码 代码如下:

var arr = [ "xml", "html", "css", "js" ];
$.inArray("js", arr);  //返回 3,

如果不包含在数组中,则返回 -1;

以上就是本文的全部内容了,有需要的小伙伴参考下吧

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!