I feel stupid, but ... how to access object value using key?
Using a colorful example instead of the actual code I'm writing, since the problem seems really simple. I just can't figure it out.
var lastnames = {
'Fred': 'Flintstone',
'Barney': 'Rubble',
'Wilma': 'Flintstone',
'Betty': 'Rubble',
'Elroy': 'Jetson'
}
The "first names" (keys) are unique and always will be.
How do I pass the first name to the object and get the last name in return?
so if I want to have a function like "gimmeLastName(firstname)" how do I access the values in the object???
Seriously, I have spent hours looking all over Jquery Docs, a JQuery book, and this forum and cannot find a single example of how to access
the values from the key:value pairs.
Instead, I find numerous references to the ".each" function, but I don't want to iterate through the list, I want to get the value by passing the key.
The other reference I found was to the the ".get" function, but when I try to do this:
var first_name = 'Fred';
var last_name = $.get(lastnames[first_name]);
alert("The last name is " + last_name));
What I get in the alert box is this:
"The last name is [XMLHttpRequest]"
I feel like I am killing myself to do something really simple.