我想從複雜的API結構中獲取數據。我將如何得到所有的圖像從以下對象和數組:如何從複雜的對象/數組結構中獲取數據?
const x = { cars: [
{ types:
{
name: "VW",
image: [{ url: "http://www.lkjl.com" }]
}
},
{...},
{...}
]};
我知道我可以得到圖像的URL是這樣的:
x.cars[0].types.image[0].url
但我怎麼能打印出來所有的圖像網址?
x.cars.map(item => {
return(
item.image[0].url; // this is wrong
);
});
我是否需要在地圖功能中有另一張地圖?
請後返回的對象,所以我們可以看到圖像如何適用。 – Hektor
會有多張圖片? – zabusa