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

143
Views
Mapping two arrays to create one array

I have two arrays which id like to merge into one array, however, the arrays have some complexities which I can't wrap my head around.... In short, I have an array of "last message" from a conversation, and I have an array of participants from that conversation.

The "messages" array looks like this

messageArray =
[
  [
    { message } <=== convo 1
  ],
  [
    { message } <===  convo 2
  ],
]

The "participant" data array looks like this

participantArray = 
[
   [
     {participant},{participant} <=== participants in convo 1
   ],
   [
     {participant},{participant},{participant} <=== participants in convo 2
   ]
]

What i'd like to have is

mergedArray =
[
  [ { message }, [ { participant }, { participant  } ]] <=== conversation 1
],
[
  [ { message }, [ { participant }, { participant  } ]] <=== conversation 2
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Based on your description, you can map the first array, and use the index to get the associated items in the second array.

eg.

const messages = [
  ["Helo World, Messsage One"],
  ["Goodbye, fair well"],
];

const users = [
   ["Bob", "Jane", "Harry"],
   ["Mike", "John", "Amanda"]
];

const joined = messages.map((m, ix) => {
  return [m[0], users[ix]];
});

console.log(joined);

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!