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);】.
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,
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!