Home > Web Front-end > JS Tutorial > How to determine if an array contains specified elements in jquery

How to determine if an array contains specified elements in jquery

coldplay.xixi
Release: 2020-11-30 15:02:06
Original
2439 people have browsed it

The jquery method to determine whether the array contains the specified element: first traverse the entire array; then determine whether they are equal. The code is [var arr = [ "xml", "html", "css", "js" ]; $.inArray("js", arr);】.

How to determine if an array contains specified elements in jquery

The operating environment of this tutorial: Windows 7 system, jquery version 3.2.1. This method is suitable for all brands of computers.

Jquery method to determine whether an array contains a specified element:

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

code is as follows:

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

If it is not included in the array, it returns -1;

Related free learning recommendations: javascript (video)

The above is the detailed content of How to determine if an array contains specified elements in jquery. For more information, please follow other related articles on the PHP Chinese website!

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