0
我試圖從這個嵌套對象中獲取一個值。似乎該對象的語法很好。我錯過了什麼?未定義的屬性嵌套的JavaScript對象
console.log(thePosts['THE PARENT ONE']['sections']['ONE SECTION']['subs']['img'][3]);
window.thePosts = {}
window.thePosts = {
'THE PARENT ONE' : {
'url':'the-url',
'sections': [{
'ONE SECTION' : {
'url':'making-money',
'subs': [
{'_id:':'1','title': 'title 1','img': '<img src="/wp-content/assets/images/pop1.jpg">'},
{'_id:':'1','title': 'title 2','img': '<img src="/wp-content/assets/images/pop1.jpg">'},
{'_id:':'1','title': 'title 3','img': '<img src="/wp-content/assets/images/pop1.jpg">'},
{'_id:':'1','title': 'title 4','img': '<img src="/wp-content/assets/images/pop1.jpg">'}
]
},
'TWO SECTION' : {
'url':'marketing',
'subs': [
{'_id:':'1','title': 'title 1','img': '<img src="/wp-content/assets/images/pop1.jpg">'},
{'_id:':'1','title': 'title 2','img': '<img src="/wp-content/assets/images/pop1.jpg">'},
{'_id:':'1','title': 'title 3','img': '<img src="/wp-content/assets/images/pop1.jpg">'},
{'_id:':'1','title': 'title 4','img': '<img src="/wp-content/assets/images/pop1.jpg">'}
]
}
}]
}
};
我猜你的意思是'[ '潛艇'] [3] [ 'IMG']'? – Danny
'thePosts ['THE PARENT ONE'] ['sections']'是一組對象! – Bergi