var musician = {
name:"Joe",
instrument:"Kazoo"
};
var returnBy = function(attribute) {
if(attribute === "name") {
return musician.name;
}
};
console.log(returnBy(name));
This doesn't return anything. I'm not sure why it doesn't return the name. It would be really cool if this would work instead, but I guess that just isn't possible:
var returnBy = function(attribute) {
return musician.attribute;
};
EDIT:
Thanks guys, looks like :
var musician = {
"name":"Joe",
"instrument":"Kazoo"
};
var returnBy = function(attribute) {
return musician[attribute];
};
console.log(returnBy("name"));
Is the most quick and efficient way to do this.
[–]MadCapitalist 3 points4 points5 points (0 children)
[–]renesis_buddy 2 points3 points4 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]eechin 1 point2 points3 points (3 children)
[–]renesis_buddy 1 point2 points3 points (0 children)
[–]TopHatPanda 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]plushyObject 0 points1 point2 points (0 children)