Javascript Object.keys() help

I must be missing something obvious, can someone explain, please, how this code

const hasExtraProps = message => {
  const allowed = ['_msgid', 'ui_update', 'class', 'visible', 'enabled']
  console.log(`message: ${JSON.stringify(message)}`)
  const keys = Object.keys(message)
  console.log(`keys: ${JSON.stringify(keys)}`)
  
  return keys.length > 0 && keys.some(key => !allowed.includes(key))
}

can show this in the log?

message: {"ui_update":{"color":"#E67E22"},"_msgid":"f047d5bf7047ad56"}
keys: ["ui_update","_msgid","payload"]

Where is the key "payload" coming from?

You would need to share the line that calls the function.

My initial guess would be that the input message has a payload property but that its value is undefined?

Agreed - that suggests payload has a value that isn't JSON encodable; could be undefined, could be some other object type that doesn't serialize.

1 Like

Yes, you are exactly right, it is undefined. I had expected JSON.stringify() to show it with value undefined, but apparently not.

Thanks both.

1 Like