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

137
Views
Get all objects in an array for same property value from an array of data

data Array

let data = [
{name: "ABC", email: "abc@gamil.com"},
{name: "xyz", email: "xyz@gamil.com"}, 
{name: "different name", email: "abc@gamil.com"}, 
{name: "xyz", email: "cde@gamil.com"}
]

I need result where all objects from an array having same email gets combined into one array as an value and key should be the email. for example the answer of above email should be:

[{
"abc@gmail.com": [
{name: "ABC", email: "abc@gamil.com"},
{name: "different name", email: "abc@gamil.com"}]
},
{"xyz@gamil.com": [
{name: "xyz", email: "xyz@gamil.com"}]
},
{"cde@gamil.com": [
{name: "xyz", email: "cde@gamil.com"}]
}
]

Objective is to get all the duplicate data on the base of email from the available data.

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

0

const data = [
  { name: 'ABC', email: 'abc@gamil.com' },
  { name: 'xyz', email: 'xyz@gamil.com' },
  { name: 'different name', email: 'abc@gamil.com' },
  { name: 'xyz', email: 'cde@gamil.com' },
];
const result = data.reduce((acc, curr) => {
  const key = curr.email;
  if (acc[key]) {
    acc[key].push(curr);
  } else {
    acc[key] = [curr];
  }
  return acc;
}
  , {});
console.log(result);

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!