I'm trying to get the following to return the appropriate key but keep getting only 9. Help and thank you.
var strZip = "96161";
var regionCodes = {
4: '00501',
4: '00544',
4: '06390',
2: '96161',
2: '96162',
getKey: function(value){
for(var key in this){
if(this[key] == value){
return key;
}
}
return 9; // Default 9 if not found
}
};
var zipKey = regionCodes.getKey(strZip);
I've also tried (and failed) with the variation that reads:
getKey: function(value){
for(var key in this){
if( this.hasOwnProperty( key) ) {
if(this[key] === value){
return key;
}
}
}
return 9; // Default 9 if not found
}