Search
 
SCRIPT & CODE EXAMPLE
 

CSS

Loop Over Array of Objects and Combine them if they have similar keys

//Convert This
var array = [
   {id=1, name = "Orange"},
   {id=1, name = "Blue"},
   {id=1, name = "Green"},
   {id=2, name = "Blue"},
   {id=3, name = "Orange"},
   {id=3, name = "Blue"}
]

//to this
var newArray = [
   {id=1, nameList = [Orange, Blue, Green]},
   {id=2, nameList = [Blue]},
   {id=3, namelist = [Orange, Blue]}
]

var array = [   {id:1, name : "Orange"},   {id:1, name : "Blue"},   {id:1, name : "Green"},   {id:2, name : "Blue"},   {id:3, name : "Orange"},   {id:3, name : "Blue"}]

var result = Object.values(array.reduce((a, c) => {
  (a[c.id] || (a[c.id] = {id: c.id, nameList: []})).nameList.push(c.name);
  return a;
}, {}));

console.log(result);
Comment

PREVIOUS NEXT
Code Example
Css :: css preloader, preload website screen 
Css :: how to add google fonts to css in react 
Css :: resctrict css to apply on div 
Css :: CSS The object-fit Property 
Css :: less set media size 
Css :: make element fill page 
Css :: build responsive real-world websites with html and css download 
Css :: profile page html css template 
Css :: table content center 
Css :: google font smooth 
Css :: add title to slider 
Css :: transform in css 
Css :: how mto change the label font style in css 
Css :: applying multiple transform values to an object css 
Css :: dark-mode 
Css :: black background overlay filter | black overlay for image css 
Css :: css template 
Css :: vim unset number 
Css :: 404 page template css 
Css :: nth-child css 
Css :: sass use 
Css :: wrap css grid 
Css :: css style link 
Css :: background image not showing html in django 
Css :: dxxxxxxx 
Css :: css clip path alternative 
Css :: css how to make something stay on screen 
Css :: gh: stop using --force !!! 
Css :: div with no content have a width/height 
Css :: Screen reader text for SEO 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =