Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Merger Douplicate array Object

var myArr=[{ "Company": "Samsung", "model": "Galaxy S2", "screen_size": "5.5" }, { "Company": "Samsung", "model": "Galaxy S3", "screen_size": "5.5" }, { "Company": "Samsung", "model": "Galaxy S4", "screen_size": "5.5" }, { "Company": "Xiaomi", "model":"Redmi 2", "screen_size": "4.7" }, { "Company": "Xiaomi", "model": "Redmi 4", "screen_size": "5" }, { "Company": "Xiaomi", "model": "Redmi Note 4", "screen_size": "5.5" } ],
    result = Object.values(myArr.reduce((r,o) => {
      r[o.Company] = r[o.Company] || {'Company': o.Company, 'Models' : []};
      r[o.Company]['Models'].push({[o.model]:{'screen_size' : o.screen_size}});
      return r;
    }, {}));

console.log(result);
Comment

PREVIOUS NEXT
Code Example
Javascript :: initial min js 
Javascript :: pg ssl settings js 
Javascript :: jlkj 
Javascript :: how to bind the dropdown data using ajax in .net mvc 
Javascript :: make the background color of page in the loading js 
Javascript :: html link file in another folder 
Javascript :: javascript plugin bootstrap 
Javascript :: use recursation in iife in js 
Javascript :: pwa tabs chrome extension 
Javascript :: simple callback pattern 
Javascript :: change nav color on scroll vanilla js 
Javascript :: react native custom ssl cer 
Javascript :: how to disable spaces and tabs for a input:text 
Javascript :: hot add value in javascript 
Javascript :: hidden vue js 
Javascript :: 3.4. Output With console.log¶ 
Javascript :: Setting Up Multiple Event Responses 
Javascript :: all running instances of node server 
Javascript :: 7.2. Bracket Notation¶ 
Javascript :: knex update and fetch result mysql 
Javascript :: tableexport dates 
Javascript :: && in react jsx 
Javascript :: array destructuring mdn 
Javascript :: localstorage API JS get Item 
Javascript :: mongoose ensureindex 
Javascript :: zoom and pan in d3.js 
Javascript :: angular dynamic script loading 
Javascript :: create serverless hello-world 
Javascript :: Add rows to the table dynamically with the use of vue.js 
Javascript :: ip address pattern regex javascript 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =