に私はこのようなオブジェクトがあります:私はfirstIndexの値を取得し、別の配列に入れたい転送値別の配列
var animals_data = {
category : [
{
class : "Reptiles",
animals : [
{
image1 : "some image",
image2 : "some image 2",
name : "Snake",
description : "some description"
},
{
image1 : "another image",
image2 : "another image 2",
name : "Crocodilia",
description : "another description"
},
]
},
{
class : "Mammals",
animals : [
{
image1 : "more image",
image2 : "more image 2",
name : "Cat",
description : "more description"
},
{
image1 : "image",
image2 : "image 2",
name : "Dog",
description : "long description"
}
]
},
{
class : "Birds",
animals : [
{
image1 : "bird image",
image2 : "bird image 2",
name : "American flamingo",
description : "bird description"
},
{
image1 : "another bird image",
image2 : "another bird image 2",
name : "Atlantic puffin",
description : "another bird description"
},
]
}
]};
を。しかし、私はこれを行うには本当に苦労しています。私がしたコードは:
for (var i = 0; i < animals_data.category.length; i++) {
var currentIteration = animals_data.category[i];
var currentClass = currentIteration.class;
animals_array.push(currentClass);
};
私はコードを実行すると、エラーが表示されます:プロパティ 'firstIndex'の未定義を読み取ることができません。ご協力ありがとうございました。
編集:私が実際に使用しているオブジェクトが含まれています。私はいくつかの部分を省略しましたが、基本的に、それは要点です。私が新しい配列に入れたい値は、 "class"プロパティの値です。
リテラルあなたのオブジェクトに問題があります。実際の例を構築してください。 –
現在のコードは、 'Uncaught SyntaxError:Unexpected token 'を生成します。' – Xotic750
'for'文の最後に'; 'を置きます。' i ++'と '{'の間に空白を入れてください。それが現れたら、すぐにループを終了します。 – raina77ow