我有以下的數組,但每當我試圖找出長度categoryData.length
它給我的只有undefined
。如果我輸入console.log(categoryData)
它會給我陣列中的所有對象。
var categoryData = {
animals: {
name: "Animals",
description: "All your favorites from aardvarks to zebras.",
items: [
{
name: "Pets"
},
{
name: "Farm Animals"
},
{
name: "Wild Animals"
}
]
},
colors: {
name: "Colors",
description: "Fresh colors from the magic rainbow.",
items: [
{
name: "Blue"
},
{
name: "Green"
},
{
name: "Orange"
},
{
name: "Purple"
},
{
name: "Red"
},
{
name: "Yellow"
},
{
name: "Violet"
}
]
},
vehicles: {
name: "Vehicles",
description: "Everything from cars to planes.",
items: [
{
name: "Cars"
},
{
name: "Planes"
},
{
name: "Construction"
}
]
}
};
@ user1689607:該問題已關閉。 –