0

Given:

let item = {
  id: xxx,
  name: yyy
};
console.log(typeof item.id, item.id, Object.keys(item.id).length)

I get:

object, null, TypeError: Cannot convert undefined or null to object

I'm confused. How can I determinte the correct type?

thanks

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
tadalendas
  • 1,461
  • 3
  • 16
  • 37
  • 1
    You have an extra `.id` in your arguments call. It should be `Object.keys(item).length` – Washington Guedes Nov 21 '16 at 15:12
  • `typeof null` is object. See this [answer](http://stackoverflow.com/a/18808252/2964675) – MarcoL Nov 21 '16 at 15:13
  • it does work as long as the `xxx` and `yyy` are valid things, try replacing them with something like a string. – Kevin Kloet Nov 21 '16 at 15:13
  • Please provide a [mcve]. You're logging 3 different things, which one is giving you the result you don't understand? Your test case uses the variables `xxx` and `yyy`, which you never define, so it stops on line one with a reference error. – Quentin Nov 21 '16 at 15:13
  • MarcoL, thanks. Please answer, so I can accept it. – tadalendas Nov 21 '16 at 15:16

0 Answers0