JSFiddle - React, Tailwind, and code Playground
by nevkatz
JavaScript
let arr = [
{
name:'apple',
type:'fruit',
fruit:true
},
{
name:'apple',
type:'fruit',
fruit:true
},
{
name:'brocolli',
type:'vegetable',
fruit:false
},
{
name:'string bean',
type:'vegetable',
fruit:false
}
];
let o = Object.groupBy(arr, o => o.fruit);
console.log(o);