Object.keys null JavaScript Origin: On your device Last updated 9 Oct 2026

TypeError: Cannot convert undefined or null to object

Object.keys/entries/assign was called with undefined or null.

Exact message you may see Cannot convert undefined or null to object
Seen on: JavaScript

Meaning

Object helpers require an object. The value you passed hasn’t loaded or the property doesn’t exist.

Common causes

  • Object.keys(data.items) where items is undefined
  • Object.assign(null, …)
  • Optional API fields

⚡ Quick fix

  1. Default to {}: Object.keys(obj ?? {})
  2. Check data has loaded
  3. Validate API responses

Detailed fix by platform

JavaScript

  1. const keys = Object.keys(response.meta ?? {});

How to diagnose

  1. Call — Which Object.* call?
  2. Value — Why undefined?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

addEventListener on null — TypeError: Cannot read properties of null (reading 'addEventListener') (JavaScript)addEventListener on n…Array offset on null — Warning: Trying to access array offset on value of type null (PHP)Array offset on nullread-only property — TypeError: Cannot assign to read only property 'x' of object (JavaScript)read-only propertyreading length — TypeError: Cannot read properties of undefined (reading 'length') (JavaScript)reading lengthTypeError — TypeError: Cannot read properties of undefined (reading 'x') (JavaScript)TypeErrorTypeError not iterable — TypeError: x is not iterable (JavaScript)TypeError not iterableTypeError set undefined — TypeError: Cannot set properties of undefined (setting 'x') (JavaScript)TypeError set undefin…Undefined property — Warning: Undefined property: Class::$prop (PHP)Undefined propertyObject.ke…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.