Given array parameter ary ["value", "value2"]
I want to loop through an object of objects to find a match for both array values. I've tried as such:
function findMatch (ary) {
storageArray = [];
mykeys = [];
myvalues = [];
for (var i = 0; i < ary.length; i++) {
for (obj in object) {
for (key in object[obj]) {
if (ary[i] in object[obj]) {
mykeys.push(key);
myvalues.push(object[obj][ary[i]]);
}
}
}
storageArray .push(mykeys, myvalues);
return storageArray;
}
var object = {
"subobject" :
{
'key' : 'value',
'key2' : 'value2',
'key3' : 'value3'
},
"subobject2" :
{
'key4' : 'value4'
},
}
Goal: be able to return the k : v pair for each match of a value in ary
meaning... since ary has value and value2... I want to return a match from the object of key : value and key2 : value2.
So far this a) isn't working and b) doesn't seem like the most efficient way to do it (3 for loops...)
[{"key":"value"},{"key2":"value2"}]? And what ifobjecthas another item"subobject3:{"key":"value"}?subobject3has only one match ("value"). What's the expected output then?