I have an array that looks similar to this:

arr['thisKey'] = { prop1 : 'a', prop2 : 'b', prop3 : 'c' }
arr['thatKey'] = { prop1 : 'x', prop2 : 'y', prop3 : 'z' }
arr['otherKey'] = { prop1 : 'red', prop2 : 'orange', prop3 : 'blue' }

I am trying to write a function (that is fast and efficient) that will return the key (or array of keys if there are more than 1) of the outer-most array based on a key/value pair nested within. Something like:

function getKey(theArray, prop, val) {
   // do some stuff
   return key;

var myKey = getKey(arr, 'prop2', 'orange');
The value of myKey should be "otherKey".

I'm pretty sure this can be done with a couple of nested for loops but these arrays are rather large and I'm thinking that, especially using jquery's grep(), there has to be a better way... or maybe not - I'm just stumped at the moment.

Any insight would be greatly appreciated!!