オブジェクト内にネストされているオブジェクトのプロパティにアクセスしようとしています。間違った方法でアプローチしていますか、構文が間違っていますか、またはその両方ですか? 内部にはさらに多くの連絡先オブジェクトがありましたが、この投稿を縮小するためにそれらを削除しました。
var friends = {
steve:{
firstName: "Rob",
lastName: "Petterson",
number: "100",
address: ['Thor Drive','Mere','NY','11230']
}
};
//test notation this works:
//alert(friends.steve.firstName);
function search(name){
for (var x in friends){
if(x === name){
/*alert the firstName of the Person Object inside the friends object
I thought this alert(friends.x.firstName);
how do I access an object inside of an object?*/
}
}
}
search('steve');