in array jquery – Jquery check if value exists in Array Example

in array jquery – The jQuery inArray() method is used to find a specific value in the given array. This jQuery array method search the the item within the array.

in array jquery

The jQuery function $.makeArray() is used to convert an object into a array. Example: Creating an Array using jQuery. If you need to check if value exists in jquery array then you can do it using jquery inarray function.

How to check if value exists in an array using Javascript?

index.html

<!DOCTYPE html>
<html>
<head>
    <title>Jquery check if value exists in Array Example - www.pakainfo.com</title>
    <script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
</head>
<body>
   
<script type="text/javascript">
   
    var players_arr = ['Sachin', 'Iyer', 'Uthhapa'];
   
    console.log($.inArray('Iyer', players_arr));
   
    if ($.inArray('Iyer', players_arr) >= 0) {
      console.log('Iyer is exist!');
    }else {
      console.log('Iyer does not exist!');
    }
   
</script>
</body>
</html>

Don’t Miss : Jquery Array

Free Live Chat for Any Issue

Using jQuery

code to check if a value exists in an array using jQuery

<script type = 'text/javascript' >

var players_arr = ['Rohit', 'Iyer', 'Sachin', 'Uthhapa', 'Finch', 'Changan'];
var text = "Murlidharan";

// Searching in Array
console.log('Index : ' + jQuery.inArray('Finch', players_arr));
console.log('Index : ' + jQuery.inArray('Virat', players_arr));

// Searching in String variable
console.log('Index : ' + jQuery.inArray("m", text));

</script>

I hope you get an idea about in array jquery.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, donโ€™t forget to share.

Rate this post