JavaScript Object Methods CheatSheet (Quick Reference)
If you only save one page for JavaScript objects — make it this one.
📚 Official Docs: MDN Docs
📌 Index
- Object.keys()
- Object.values()
- Object.entries()
- Object.fromEntries()
- Object.assign()
- Object.hasOwn()
- Object.freeze()
- Object.seal()
- Object.create()
- Object.getPrototypeOf()
🚀 Methods Explained
1. Object.keys()
What it does: Returns all keys of an object
Example:
Object.keys({ a: 1, b: 2 });Output:
["a", "b"]2. Object.values()
What it does: Returns all values of an object
Example:
Object.values({ a: 1, b: 2 });Output:
[1, 2]3. Object.entries()
What it does: Returns key-value pairs as arrays
Example:
Object.entries({ a: 1, b: 2 });Output:
[["a", 1], ["b", 2]]4. Object.fromEntries()
What it does: Converts entries back to object
Example:
Object.fromEntries([["a", 1], ["b", 2]]);Output:
{ a: 1, b: 2 }5. Object.assign()
What it does: Merges objects (shallow copy)
Get Praveen Sripati’s stories in your inbox
Join Medium for free to get updates from this writer.
Example:
Object.assign({}, { a: 1 }, { b: 2 });Output:
{ a: 1, b: 2 }6. Object.hasOwn()
What it does: Checks if property exists (own property only)
Example:
Object.hasOwn({ a: 1 }, "a");Output:
true7. Object.freeze()
What it does: Prevents any changes to the object
Example:
const obj = Object.freeze({ a: 1 });
obj.a = 2;Output:
{ a: 1 } // unchanged8. Object.seal()
What it does: Allows updating values but prevents adding/removing keys
Example:
const obj = Object.seal({ a: 1 });
obj.a = 2;
obj.b = 3;Output:
{ a: 2 } // 'b' not added9. Object.create()
What it does: Creates a new object with a given prototype
Example:
const proto = { a: 1 };
const obj = Object.create(proto);obj.a;Output:
110. Object.getPrototypeOf()
What it does: Returns the prototype of an object
Example:
Object.getPrototypeOf({});Output:
Object.prototype🎯 Quick Mental Model
keys()→ keysvalues()→ valuesentries()→ key + valuefromEntries()→ reverseassign()→ mergefreeze()→ lockseal()→ partial lock
🔥 Pro Tips
- Prefer
Object.hasOwn()overhasOwnProperty()✅ - Use
entries → map → fromEntriesfor transformations 🚀 Object.assign()is shallow copy ⚠️- Use
Object.freeze()for constants









