user7012900
user7012900

Reputation:

Javascript console.log not reading array undefined

I am having issues with reading some data where I'm getting undefined:

obj = {
    "people": [
        {
            "id": "123",
            "description": "some desc",
            "names": [
                {
                    "name": "Mark"
                }]
        }]

}

console.log(obj.people[0].names.name);

What I'm I doing wrong here?

Upvotes: 2

Views: 4084

Answers (2)

Kushan
Kushan

Reputation: 10695

names is also an array.

Try this,

console.log(obj.people[0].names[0].name);

Upvotes: 0

gurvinder372
gurvinder372

Reputation: 68393

names is an array, make it

console.log(obj.people[0].names[0].name);

Upvotes: 2

Related Questions