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

577
Views
How can I inner join with two object arrays in JavaScript?

I need inner join with two array in javascript like this:

    
    array1 = 
    [
      {
        "id": 1,
        "name": "Tufan"
      },
      {
        "id": 2,
        "name": "Batuhan"
      },
      {
        "id": 3,
        "name": "Hasan"
      }
    ]
    
    array2 = 
    [
      {
        "name": "yyy",
        "externalid": "1",
        "value": "Asd"
      },
      {
        "name": "aaaa"
        "externalid": "2",
        "value": "ttt"
      }
    ]
    
    expectedArray = 
    [
      {
        "id": 1,
        "name": "Tufan",
        "externalid": "1",
        "value": "Asd"
      },
      {
        "id": 2,
        "name": "Batuhan",
        "externalid": "2",
        "value": "ttt"
      }
    ]

rules:

  1. on: array2.externalid = array1.id
  2. select: array1.id, array1.name, array2.externalid, array2.value

My approach:

array1.filter(e => array2.some(f => f.externalid == e.id));
// I need help for continue

How can I make this?

Doesn't matter information: I use ES5 and pure javascript

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

0

You can do it like this:

const res = array2.map((item) => {
  const related = array1.find((el) => el.id == item.externalid);
  return { ...item, ...related };
});

Using a map to loop over the array2 and a find to get the array1 relative.

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!