Javascript check InArray Functions

This functions returns ‘true’  and the element, if the passed value is in the to-be-checked array and like-wise.

CheckValueInArray = function(arr,val){
var inArray = false;
var whereIn = 'notIn';
for(a=0; a<arr.length; a++)
if (val == arr[a]){
inArray = true;
whereIn = a;
}
return {inArray:inArray,whereIn:whereIn}; //returning multiple values
}

Advertisements
Javascript check InArray Functions

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s