Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

JavaScript groupBy is not a functio

i want to group my Data with the Name of type

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 }          
       let result = inventory.groupBy( ({ type }) => type );

on above getting error as groupBy is not a functio

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

JavaScript arrays don’t have a groupBy method yet. See MDN’s documentation. It’s in nightly Firefox builds at the moment and that’s all. The proposal is Stage 3 so it’ll be landing in JavaScript engines before too long, but in the meantime you have to polyfill it. There are various ways to polyfill it, for instance via core-js. (Babel used to do polyfilling, but now recommends using core-js directly.)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading