I have an object like this:
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"
},
]
}
]};
I want to get the values of the firstIndex and put them in a different array. However, I am having a really hard time doing this. The code I did is:
for (var i = 0; i < animals_data.category.length; i++) {
var currentIteration = animals_data.category[i];
var currentClass = currentIteration.class;
animals_array.push(currentClass);
};
When I run the code the error says: Cannot read property 'firstIndex' of undefined. Thank you for your help.
Edit: included the actual object I am working with. I have omitted some parts but basically, that's the gist. The values I want to put in a new array are the ones in the "class" property.
Uncaught SyntaxError: Unexpected token ]
;
at the end offor
statement: there should be nothing but whitespace betweeni++)
and{
. As it stands, you immediately finish your loop.Uncaught ReferenceError: obj is not defined