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

147
Views
How to merge two arrays by the name value in JavaScript by using includes

How to merge this 2 arrays by name though the whole name in arr1 has the name Ana Marie Cruz while the arr2 has the name Anna Marie . Can someone give me an idea. I have attempted it in es6.What can be the most efficient way to do it.

let arr1 = [{
  name: "Shaina",
  age: "27"
}, {
  name: "Ana Marie Cruz",
  "age": "35"
}];
let arr2 = [{
  name: "Ana Marie",
  status: "married"
  gender: Female
}];

I'm trying to get this output in javascript.

var arr3 = [{name: "Shaina", age: "27"},{name:"Ana Marie Cruz", age : "35",status:"married",gender:Female}];
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

you can do something like this

let arr1 = [{
  name: "Shaina",
  age: "27"
}, {
  name: "Ana Marie Cruz",
  "age": "35"
}];
let arr2 = [{
  name: "Ana Marie",
  status: "married",
  gender: 'Female'
}];

let arr3 = arr1.map(a => {
 const founded = arr2.find(({name}) => a.name.includes(name))
 
 return {
   ...(founded || {}),
   ...a
 }
 
})
console.log(arr3)

about 4 years ago · Juan Pablo Isaza Report

0

const arr1 = [
  {
    name: "Shaina",
    age: "27",
  },
  {
    name: "Ana Marie Cruz",
    age: "35",
  },
];

const arr2 = [
  {
    name: "Ana Marie",
    status: "married",
    gender: "Female",
  },
];

const result = arr1.map((d) => {
  const data = arr2.find((a) => d.name.includes(a.name));
  if (!data) return d;
  return {
    ...d,
    ...data,
  };
});

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!