views:

90

answers:

2

I want to determine (using JQuery) if my $(this).data contains an array with a member=x. $(this).data looks like this:

  'key1':[1,28,3,4],
  'key2':[5,6,7,8,9],
  'key3':[15,32]

Normally, I'd figure on looping through the keys and checking to see if each value array contained x, but JQuery has all these weird and wonderful functions, I thought there might be an easier way.

A: 

http://api.jquery.com/jQuery.inArray/

wonderful functions :)

Edit: I think you still needs to wrap inArray in something like

$.each( yourArray, functionWithinArray() );
Adam Kiss
+1  A: 

not really elegant, but this works:

var notfound = true;
$.each($(this).data, function(key, arr) {
    return notfound = ($.inArray(x, arr) === -1);
});

and your answer will be in notfound

cobbal