0

I have a method with a parameter called project. If I log this, it is a bigger object with a lot of properties. One of them is "metrics".

console.log(project)
// this will show the whole object with my needed "`metrics`". Just to make it clear. Inside of project is the property metrics with the data I need.

Now I specifically need metrics. So, I tried this:

console.log(project.metrics)

This is always undefined. How can that be if the above log shows me the object with the metrics. I tried a workaround with setTimeout to "wait", I tried Promises with async/await. Somehow metrics gets lost although I could log it one line before.

Does anyone have an idea?

node_modules
  • 4,790
  • 6
  • 21
  • 37
Klaxx
  • 380
  • 1
  • 6
  • 22
  • Does the log only show the object properties once you "expand" it in the console? Or can you see the properties without expanding? – Nick Parsons Jan 19 '23 at 10:04
  • The console evalueates objects lazily. Look for a line like `something.metrics = ...` – Thomas Jan 19 '23 at 10:08
  • 1
    If you log `console.log(JSON.stringify(project))`, you probably won't see `metrics` property at all because it is undefined when `project` was logged. – adiga Jan 19 '23 at 10:14

0 Answers0