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

How to determine if an element is in an array in jquery

coldplay.xixi
Release: 2021-02-03 17:03:39
Original
2915 people have browsed it

Jquery method to determine whether an element is in an array: Use the [$.inArray] method to determine whether the specified element is in the array. The [$.inArray()] function is used to find the specified value in the array and return it. Its index value, the syntax is [$.inArray( value, array[, from].

How to determine if an element is in an array in jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version , Dell G3 computer.

Jquery method to determine whether an element is in an array:

In jquery, you can use the $.inArray method to determine the specified element Whether it is in the array. $.inArray()The function is used to find the specified value in the array and return its index value (if not found, it returns -1).

Syntax :

$.inArray( value, array [, fromIndex ] )
Copy after login

Parameters:

  • valueAny type of value used for lookup.

  • array ArrayThe type specifies the array to be searched.

  • fromIndexOptional. The Number type specifies that the search starts from the specified index position of the array, the default is 0

##Example:

var arry = [ "C#", "html", "css", "JavaScript" ];
var result= $.inArray("C#", arry);
Copy after login
Related free learning recommendations:

js video tutorial

The above is the detailed content of How to determine if an element is in an array 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