Object Omit And Pick Utility
Safely omit or pick keys from objects returning typed results for immutable data transformation.
Code
export function omit(obj,keys){const keySet=new Set(keys);return Object.fromEntries(Object.entries(obj).filter(([k])=>!keySet.has(k)));}export function pick(obj,keys){return Object.fromEntries(keys.filter(k=>k in obj).map(k=>[k,obj[k]]));}export function pickBy(obj,predicate){return Object.fromEntries(Object.entries(obj).filter(([k,v])=>predicate(v,k)));}export function omitBy(obj,predicate){return Object.fromEntries(Object.entries(obj).filter(([k,v])=>!predicate(v,k)));}How it works
Count the functions omit, pick, pickBy and omitBy as the entire surface area of Object Omit And Pick Utility.
Using it
The main signature reads export function omit(obj,keys)
omit is the public entry point; everything else in the file exists to support it.
Interactive Tools for This Topic
FAQ
- Are there dependencies to manage?
- No. There are no dependencies to declare or install. The file defines `omit`, `pick`, `pickBy` at load time.
Report a problem with this exampleOpens a pre-filled issue on GitHub.