Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

array with object same keys

const arrays = [{ name: "foo1",value: "val1" }, {name: "foo1", value: ["val2", "val3"] }, {name: "foo2",value: "val4"}];

const map = new Map(arrays.map(({name, value}) => [name, { name, value: [] }])); 
for (let {name, value} of arrays) map.get(name).value.push(...[value].flat());
console.log([...map.values()]);
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: react datepicker 
Javascript :: how to add abutton component to drawer in react native 
Javascript :: react video 
Javascript :: if or react 
Javascript :: js array as parameter 
Javascript :: tobe a number jest 
Javascript :: google autocomplete not returning lat long 
Javascript :: jquery add css important 
Javascript :: Relative Time momentjs 
Javascript :: capitalize first letter in array of strings javascript 
Javascript :: for of in js or for in loop in js 
Javascript :: ng select2 angular dropdown 
Javascript :: math.round in javascript 
Javascript :: remove duplicates javascript 
Javascript :: parsedate javascript 
Javascript :: vue google map api for user marker location 
Javascript :: alert javascript react native 
Javascript :: jquery validate all input fields 
Javascript :: js promise 
Javascript :: set array length js 
Javascript :: how set type of string value to number in js 
Javascript :: vs code file nesting 
Javascript :: material icon button angular 
Javascript :: event after div created 
Javascript :: mdn object assign 
Javascript :: vue style background color 
Javascript :: object comparison in javascript 
Javascript :: console.log(...) is not a function 
Javascript :: connect to existing collection mongoose 
Javascript :: look through object keys javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =