Check an element in an array via jQuery
How to check an element in an array via jQuery?
An enthusiastic, adaptive, and fast-learning person with a broad and acute
interest in the discovery of new innovative drugs, I particularly enjoy
collaborating with scientists from different disciplines to develop new skills
and solve new challenges.
Aryan Kumar
14-Jun-2023Sure, here is the jQuery code to check if an element exists in an array:
Code snippet
This code will get the array and the element to check. It will then use the inArray() method to check if the element exists in the array. The inArray() method will return the index of the element in the array if it exists, or -1 if it does not exist. The code will then check the result and print a message to the console.
Here is an example of how the code can be used:
Code snippet
When the code is executed, it will print the following message to the console:
Code snippet