'"Cannot read" error when trying to access Object's properties [duplicate]

I have this JS Object that contains 3 "thread" objects each with different values. I am trying to get the values from each of the threads. I am able to print the entire json object, but I can't print individual values from them?

My code: console.log(threadArray) returns this in console: (which is perfect) enter image description here

but when I try to replace "threadArray" with "threadArray[0].threads[0]["_id" to get the first thread's ID, it says it Cannot read unknown value.

Does anybody know why?



Solution 1:[1]

It's because the object called "threads" is the same as "threadArray[0]" because it IS the first element in the array. You are calling the same object twice. Instead of that log, try using this one:

console.log(threadArray[0]._id);

I hope this helps! I will stay tunned so that you can tell me if it worked

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1