I have an object that looks similar to this:
var arr = {};
arr.planes = { prop1 : 'a', prop2 : 'b', prop3 : 'c' };
arr.trains = { prop1 : 'x', prop2 : 'y', prop3 : 'z' };
arr.autos = { 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(obj, prop, val) {
// do some stuff...
return key;
}
var myKey = getKey(arr, 'prop2', 'orange');
The value of myKey should be "autos".
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!!
myKeybeautos?