Skip to content

Home

Unwind object

Produces an array of objects from an object and one of its array-valued properties.

const unwind = (key, obj) => {
  const { [key]: _, ...rest } = obj;
  return obj[key].map(val => ({ ...rest, [key]: val }));
};

unwind('b', { a: true, b: [1, 2] }); // [{ a: true, b: 1 }, { a: true, b: 2 }]

More like this

Start typing a keyphrase to see matching snippets.