Home  >  Article  >  Web Front-end  >  jQuery determines whether the array contains the specified element_jquery

jQuery determines whether the array contains the specified element_jquery

WBOY
WBOYOriginal
2016-05-16 16:10:201964browse

To determine whether an array contains an element, in principle, it is to traverse the entire array and then determine whether it is equal,

Copy code The code is as follows:

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

If not included in the array, return -1;

The above is the entire content of this article, friends in need can refer to it

Statement:
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