The Object constructor carries the reflection toolkit. keys(), values() and entries() list own enumerable string keys only. Object.hasOwn() safely replaces obj.hasOwnProperty(), even on null-prototype objects, and Object.is() differs from === only for NaN and -0. Object.groupBy() (Baseline since March 2024) returns a null-prototype object.
| Purpose | Methods |
|---|---|
| Create and copy | create, assign, fromEntries |
| List and test keys | keys, values, entries, getOwnPropertyNames, hasOwn |
| Prototypes, descriptors, locking | getPrototypeOf, defineProperty, freeze, seal |
| Compare and group | is, groupBy |
const prices = { pen: 1.5, book: 12, [Symbol("sku")]: 7 };
const half = Object.fromEntries(Object.keys(prices).map((k) => [k, prices[k] / 2]));
const dict = Object.create(null); // no prototype, no inherited keys
console.log(Object.values(prices), half, Object.hasOwn(dict, "toString"));
console.log(Object.is(NaN, NaN), Object.groupBy(["a", 1, "b"], (x) => typeof x));[ 1.5, 12 ] { pen: 0.75, book: 6 } false
true [Object: null prototype] { string: [ 'a', 'b' ], number: [ 1 ] }