I'm trying to access a particular array by it's index within an object within an object (sorry, this may be the wrong terminology).
var person = {
name: ["Tom", "Mike", "Sally"],
hair: {
style: ["bob", "weave", "mullet"],
length: ["long","short","medium"]
}
}
getDetail(length);
function getDetail(det) {
var answer = person.hair.det[1];
console.log("Hair " + det + " is " + answer) //outputs: "Hair length is long"
}
When I do this, I am getting an error of "Can't read property '1' of undefined". Which tells me it isn't passing the 'det' variable correctly. If I take that out and put length instead, it works.
What am I missing?
Thanks!