Documentation
@tsly/obj
flatten

flatten

Flattens the wrapped object into an array with each entry key and value mapped to a specified named attribute.

If only a name is specified, then given that the value of each record is an object, the keys of that subobject will be inlined into the new object.

const ages = {
  bill: 38,
  john: 21,
  adam: 25,
};
 
obj(ages)
  .flatten("name", "age")
  .take((it) => console.log(it));
 
// [{ name: 'bill', age: 38 }, { name: 'john', age: 21 }, ...]

Edit on CodeSandbox (opens in a new tab)

const people = {
  bill: { age: 38, hobbies: ["cooking"] },
  john: { age: 21, hobbies: ["gardening", "sports"] },
  adam: { age: 25, hobbies: ["hiking"] },
};
 
obj(peoples)
  .flatten("name")
  .take((it) => console.log(it));
 
// [{ name: "bill", age: 38, hobbies: ["cooking"] }, ...]

Edit on CodeSandbox (opens in a new tab)