Pick properties from an object
Build a new object with only the requested own properties.
function pick({ value, keys }) { return Object.fromEntries(keys.filter(key => Object.hasOwn(val…objectCollection · 13 utilities
Pick only the fields you need, understand shallow copies and keep prototype keys as data.
Build a new object with only the requested own properties.
function pick({ value, keys }) { return Object.fromEntries(keys.filter(key => Object.hasOwn(val…objectKeep the own enumerable fields that are not in a supplied list.
function omit({ value, keys }) { return Object.fromEntries(Object.entries(value).filter(([key])…objectTurn [key, value] pairs into a plain object with Object.fromEntries.
function toObject(pairs) { return Object.fromEntries(pairs); }objectCompare JSON serializations with the first object.
function areEqual(objects) { return objects.every(object => JSON.stringify(object) === JSON.str…objectFollow a dot-separated path, stopping at a missing step.
function getValue({ path, object }) { return path.split('.').reduce((value, key) => (value == n…objectReturn a copy with keys renamed through a mapping.
function renameKeys({ keysMap, object }) { return Object.fromEntries(Object.entries(object).map…objectSwap every key with its value.
function invert(object) { return Object.fromEntries(Object.entries(object).map(([key, value]) =…objectPluck one field from every record.
function pluck({ objects, property }) { return objects.map(object => object[property] ?? null);…objectRebuild an object with its keys in sorted order.
function sortKeys(object) { return Object.fromEntries(Object.keys(object).sort().map(key => [ke…objectDrop keys whose value is null or undefined.
function removeNullish(object) { return Object.fromEntries(Object.entries(object).filter(([, va…objectCopy own enumerable properties into a new object.
function shallowCopy(object) { return { ...object }; }objectKeep one record per key value, the last one seen.
function uniqueBy({ objects, key }) { return [...new Map(objects.map(item => [item[key], item])…objectAn object with no prototype: no inherited keys such as toString or __proto__.
function createDictionary() { return Object.create(null); }objectTry a function in the local code lab, then read its limits before using it in an application.