Home  >  Article  >  Web Front-end  >  How to determine if an element is in an array in jquery

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

coldplay.xixi
coldplay.xixiOriginal
2020-12-23 11:26:512878browse

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 ] )

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);

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!

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