Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery check if value not in array

Tags:

arrays

jquery

Tried to get this to work:

var instance_name = $('#instance_name').val();
$("#instance_name").on("blur", function(e){
    if (!~$.inArray(instance_name, not_allowed)) {
        $("#instance_alert").html("<font color=green>Instance does not exists. Please continue</font>");
    } else {
        $("#instance_alert").html("<font color=red>Instance exists. Please try another one.</font>");
    }

But to no avail.. (Looked into How to check if a value is NOT in an array using jQuery)

Any ideas why it still continues to say Please continue Kindly.

like image 245
osomanden Avatar asked Dec 24 '22 09:12

osomanden


1 Answers

you can use this: please $.inArray

if(jQuery.inArray("test", not_allowed) != -1) {
    console.log("is in array");
} else {
    console.log("is NOT in array");
} 
like image 173
Angu Avatar answered Dec 27 '22 02:12

Angu