我有一个名为data
的对象,如何使用Javascript访问键name
的值
const data = {
"bar2": {
"address": "138/140 Gouger St, Adelaide SA 5000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "Disco Mexico, blends party vibes with fuss-free Mexican food in a small-bar setting.",
"imgURLs": [
"https://url",
"https://url"
],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https://firebasestorage.googleapis.com/v0/b/vipeeps-2018.appspot.com/o/venueImages%2FDisco_Mex_o.jpg?alt=media&token=60d76240-221c-415c-8d0d-7324d95a30ba"
}
}
答案 0 :(得分:0)
const data = {
"bar2": {
"address": "138/140 Gouger St, Adelaide SA 5000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "Disco Mexico, blends party vibes with fuss-free Mexican food in a small-bar setting.",
"imgURLs": [
"https://url",
"https://url"
],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https://firebasestorage.googleapis.com/v0/b/vipeeps-2018.appspot.com/o/venueImages%2FDisco_Mex_o.jpg?alt=media&token=60d76240-221c-415c-8d0d-7324d95a30ba"
}
}
console.log(data.bar2.name)
答案 1 :(得分:0)
以任何其他方式访问属性-data.bar2.name
:
const data = {
"bar2": {
"address": "138/140 Gouger St, Adelaide SA 5000",
"appStoreURL": "http://itunes.apple.com/app/idXXXXXXXXX",
"description": "Disco Mexico, blends party vibes with fuss-free Mexican food in a small-bar setting.",
"imgURLs": [
"https://url",
"https://url"
],
"lat": -34.848082,
"lon": 138.599813,
"name": "Disco Mexico Taqueria",
"phone": "0416 855 108",
"status": "active",
"venueImgURL": "https://firebasestorage.googleapis.com/v0/b/vipeeps-2018.appspot.com/o/venueImages%2FDisco_Mex_o.jpg?alt=media&token=60d76240-221c-415c-8d0d-7324d95a30ba"
}
};
const name = data.bar2.name;
console.lo(name);
答案 2 :(得分:0)
您可以使用.
之类的data.bar2.name
表示法,也可以使用data['bar2']['name']
之类的索引表示法