My object looks like this:
aryControlDef = {
'item1' : ['a','b','c'],
'item2' : ['x','y','z']
};
yet when I call this
var sAtt = 'z';
var vControlDef = Array.prototype.filter.call(aryControlDef, function(value) {return value[2] == sAtt});
I get this:
vControlDef = []
I know it's to do with the way array-like objects with keys iterate, because this loop gets the correct result:
for(var i in aryControlDef){
if(aryControlDef[i][2]=='z'){
vControlDef[aryControlDef[i][0]] = aryControlDef[i];
};
};
what I'm after is a way to return an object containing the key(s) with attributes that match sAtt.
what I can't figure out is how to iterate the keys in the callback function, in the same way that is possible in the 'for...each' loop, and Google hasn't found me any results for this case use. TIA for any suggestions :)
-- ps. forgot to mention I am doing this in Google Apps Script which means no external libraries (and no DOM)
-- Suggested Solution 1
var vControlDef = Object.keys(aryControlDef).filter(function(key) {
return aryControlDef[key][2] == sAtt;
});
raises a non-descript Google server error "We're sorry, a server error occurred. Please wait a bit and try again.".