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

Checking item existence in an Array is a most common task in our lives. But till today I did not found any efficient Javascript in built method to achieve this. indexOf() method work in some browser not in all that’s why I am not interested to use it. To Check a Value Exist in Array in Javascript still I preferred a custom function to check the array for the element to search. If the element is found in an array it returns the position of that element.

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

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

Javascript code to Check whether a Value Exists in an Array:

<script type="text/jscript">
    var MonthList = ['January', 'February', 'March', 'April', 'May', 'June'];
    for (var i = 0; i < MonthList.length; i++) {
        if (MonthList[i] === 'May') {
            var msg = "Original Array: January, February, March, April, May, June"+"\n";
            msg += 'May Found at Index [' + i + ']';
            alert(msg);
            break;
        }
    }
</script>

Download Code Example C#        Download Code Example VB.Net

Leave a Reply

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

AlphaOmega Captcha Classica  –  Enter Security Code