重複の可能性:
配列の長さが定義されていません
私は次の配列を持っていますが、それで長さを調べようとすると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"
}
]
}
};