Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

remove object if key is duplicate javascript

let array =   [{"sector": "adad"},{"sector": "adadasdsd"},{"sector": "sdsdsd"},{"origin": "sdfsf"},{"destination":"dfsfsdf"}]

let reduced = array.reduce((a, c, i) => {
  let key = Object.keys(c)[0];
  if (!(key in a)) a[key] = [];
  if (!a[key].includes(c[key])) a[key].push(c[key]);
  return a;
}, {})

console.log(reduced)
 Run code snippet
Comment

PREVIOUS NEXT
Code Example
Javascript :: is checked jquery not working 
Javascript :: hooks developed by react native 
Javascript :: js split string 
Javascript :: modify array elements javascript 
Javascript :: js download 
Javascript :: bind method in javascript 
Javascript :: take string until react 
Javascript :: how can i do metaname csrf token attrcontent in vanilla javascrip 
Javascript :: The element.onclick Property 
Javascript :: react native modal ios landscape 
Javascript :: convert base64 to pdf file javascript 
Javascript :: object find javascript 
Javascript :: mdn destructuring 
Javascript :: claim faucets 
Javascript :: vbscript popup message box with timer 
Javascript :: autocomplete required material ui 
Javascript :: react using button props child 
Javascript :: enzyme test method 
Javascript :: mongooseautoincrement 
Javascript :: is missing in props validationeslintreact/prop-types 
Javascript :: mongodb js insertmany 
Javascript :: react use media query 
Javascript :: TypeError: db.collection Name is not a function 
Javascript :: clone canvas 
Javascript :: loop map with key value pair js 
Javascript :: repeat network call n times in js 
Javascript :: react effect hook 
Javascript :: res.write image url 
Javascript :: fcm node 
Javascript :: creat and move square using js 
ADD CONTENT
Topic
Content
Source link
Name
7+1 =