Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

group by hash in jquery

const users = [{
    name: "Jim",
    color: "blue"
  },
  {
    name: "Sam",
    color: "blue"
  },
  {
    name: "Eddie",
    color: "green"
  },
  {
    name: "Robert",
    color: "green"
  },
];
const groupBy = (arr, key) => {
  const initialValue = {};
  return arr.reduce((acc, cval) => {
    const myAttribute = cval[key];
    acc[myAttribute] = [...(acc[myAttribute] || []), cval]
    return acc;
  }, initialValue);
};

const res = groupBy(users, "color");
console.log("group by:", res);
Comment

PREVIOUS NEXT
Code Example
Javascript :: convert base64 to image javascript 
Javascript :: get seo friendly url values in javascript 
Javascript :: convert path string to url encoding javascript 
Javascript :: JS check the type stored in the name variable in JS 
Javascript :: create trigger to run every minute in apps script 
Javascript :: how to add edit and delete rows of a html table with javascript 
Javascript :: event module 
Javascript :: Javascript one parameter fat arrow 
Javascript :: Line logger 
Javascript :: React img element rating 
Javascript :: provider not found react 
Javascript :: make form submit on new window using jquery 
Javascript :: javascript compare dates old new value 
Javascript :: javascript events reference 
Javascript :: serve public folder express without file extension 
Javascript :: how to filter data in javascript object 
Javascript :: jquery elements to json 
Javascript :: gsheet get cell background color 
Javascript :: var quotes 
Javascript :: early exit js 
Javascript :: Scratch Addon userscript 
Javascript :: time ago function web 
Javascript :: js test1 
Javascript :: vue unit tests form submit 
Javascript :: local storage textarea 
Javascript :: enzym.debug 
Javascript :: discord.js v13 afk command 
Javascript :: radio button not checked when clicked react 
Javascript :: KIVIN 
Javascript :: how to use bootstrap in reactjs 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =