Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
how to automatically filter and seperate the array of object data if number of objects have the common value in javascript
  const mixedData = [{name :'Darci' , skill : 'python'},{name :'Darci' , skill : 'javascript'},{name :'Darci' , skill : 'react js'},{name :'Brooke' , skill : 'Photoshop'},{name :'Brooke' , skill : 'Indesign'},{name :'John' , skill : 'mangoDB'},{name :'john' , skill : 'mySQL'}]

 

but i want output like this

const Data = [{name: 'Darci' , skill : ['python' , 'javascript' , 'react js']},
              {name: 'Brooke' , skill : ['Photoshop' , 'Indesign']},
              {name: 'Jhon' , skill : ['mangoDB' , 'mySQL']},
]

but i dont want to hard code by filter method like below code

const finalArray = mixedData.filter(e=> e.name === 'Darci' ?{...} : {...}

)

no matter how may unique values in object filter please anyone help me out of this solution

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could also get the result using Array.reduce() to group the skills according to the user name:

const mixedData = [{name :'Darci' , skill : 'python'},{name :'Darci' , skill : 'javascript'},{name :'Darci' , skill : 'react js'},{name :'Brooke' , skill : 'Photoshop'},{name :'Brooke' , skill : 'Indesign'},{name :'John' , skill : 'mangoDB'},{name :'john' , skill : 'mySQL'}]

const result = Object.values(mixedData.reduce((acc, { name, skill }) => { 
    acc[name] ||= { name, skill: [] };
    acc[name].skill.push(skill);
    return acc;
}, {}));

console.log('Result:', result);
.as-console-wrapper { max-height: 100% !important; top: 0; }

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!