Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Object.groupBy available in browsers, polyfill needed for Node, RN #106

Open
sanjarcode opened this issue Nov 19, 2023 · 0 comments
Open
Assignees

Comments

@sanjarcode
Copy link
Member

Object.groupBy

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/groupBy

const inventory = [
  { name: "asparagus", type: "vegetables", quantity: 5 },
  { name: "bananas", type: "fruit", quantity: 0 },
  { name: "goat", type: "meat", quantity: 23 },
  { name: "cherries", type: "fruit", quantity: 5 },
  { name: "fish", type: "meat", quantity: 22 },
];

const result = Object.groupBy(inventory, ({ type }) => type);

unfortunately, not available in Node, so React won't transpile.
Can't use in React.

Works in React web
Polyfill exists for React native, so might work in Node.js too.


con: no way to exclude stuff from being grouped. workaround: return null instead of a string to collect non-participants. The final object has a null key then

@sanjarcode sanjarcode self-assigned this Nov 19, 2023
@sanjarcode sanjarcode changed the title Object.groupBy available in browsers, polyfill needed for Node Object.groupBy available in browsers, polyfill needed for Node, RN Nov 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant