JQuery to Check whether a Value Exists in Array in Asp.Net C# VB.Net

As a web developer we needs to do a lot of operations daily on Array. Array is a common data structure which help us to build from simple to complex business logic whatever from server side or from client side. Array is in everywhere. One of the common operation on Array is whether a value exist in Array or not. If exists then we need to the Array index number. Yes here in this article I am going to describe “How we can check a value exists in array or not using JQuery“. The JQuery inArray method provides us the functionality to achieve. Let’s see the implementation of inArray method from below:

Related Article:
Javascript to Check whether a Value Exists in an Array in Asp.Net C# VB.Net

Objective/Outcome:
JQuery to Check whether a Value Exists in Array - Asp.Net Csharp VB.Net

To do the Add a Label Control First:

<asp:Label ID="Label1" runat="server" Text=""></asp:Label>

JQuery Code to Check whether a Value Exists in Array:

<script type="text/javascript">
    $(document).ready(function () {
        var Months = ["January", "February", "March", "April", "May"];
        if ($.inArray("April", Months) > -1) {
            var msg = "Origianl Array: January, February, March, April, May<br/><hr/>";
            msg += "April Found at Index [" + $.inArray("April", Months) + "]<br/>";
            msg += "May Found at Index [" + $.inArray("May", Months) + "]<br/>";
            msg += "may Found at Index [" + $.inArray("may", Months) + "]  >> .inArray() is case sensitive !!";
            $('#<%=Label1.ClientID%>').html(msg);
        }
    });  
    </script>

Note: .inArray() is case sensitive.

Download Code Example C#        Download Code Example VB.Net

Posted in .Net, Asp.net, C#, Client, JQuery, VB.Net

Leave a Reply

Your email address will not be published. Required fields are marked *

AlphaOmega Captcha Classica  –  Enter Security Code
     
 

*