Seth Connell Seth Connell - 1 month ago 10
Javascript Question

Why is my Array's Value Undefined? (Javascript)

I'm trying to console.log one of the items in my "images" array. Here's the code I have written so far:



var projects = {
projects : [
{
"title" : "Jarvis Systems",
"dates" : "2015",
"description" : "A simple control panel for stuff.",
"images" : ["http://www.bitrebels.com/wp-content/uploads/2013/10/MAKO-Voice-Recognition-System-3.jpg", "https://i.ytimg.com/vi/ah6tHb7eWBY/maxresdefault.jpg"]
}
]
};

console.log(projects.projects.images[0])





Sadly, when I run the code, the console says that my array is undefined. How can that be when I just defined it?

Answer

Make it projects.projects[0] instead of projects.projects since projects is an array inside projects

var projects = {
    projects : [
        {
            "title" : "Jarvis Systems",
            "dates" : "2015",
            "description" : "A simple control panel for stuff.",
            "images" : ["http://www.bitrebels.com/wp-content/uploads/2013/10/MAKO-Voice-Recognition-System-3.jpg", "https://i.ytimg.com/vi/ah6tHb7eWBY/maxresdefault.jpg"]
        }
    ]
};

console.log(projects.projects[0].images[0])

Comments