Cheat Sheets
Objects · Study material
JavaScript Objects Cheat Sheet
| Code | Meaning |
|---|---|
{ name, [key]: v, greet() {} } | shorthand, computed key, method |
obj.a · obj["a-b"] · obj[k] | read a property |
delete obj.a | remove a property |
"a" in obj · Object.hasOwn(obj, "a") | exists (chain) · own only |
Object.entries(obj) · Object.fromEntries(pairs) | object ↔ pairs |
{ ...a, ...b } | shallow merge (b wins) |
Object.assign(t, s) | copies into t and returns t |
structuredClone(obj) | deep copy |
Object.freeze(o) · Object.seal(o) | read-only · fixed shape |
get x() {} · set x(v) {} | accessor property |
Object.defineProperty(o, "k", { value, enumerable: false }) | hidden, read-only property |
Object.create(proto) · Object.create(null) | given prototype · no prototype |
method.bind(obj) | fix this |
JSON.stringify(o) · JSON.parse(s) | object ↔ JSON text |