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

261
Views
How to group object values by key in Jquery?

I updated my question:

I have 2 objects(from user inputs)

a = {id:1, name:'a', age:10, country:''};
b = {id:2, name:'b', age:14, country:'Malaysia'}

I will need to always fill the 'a' object into my html table if the object key is match with table td's id; also if 'a' have empty value, 'b' will need to replace it, finally I will need to get the result:

result = {id:1, name:'a', age:10, country:'Malaysia'}

But I merge 2 object become:

[{id:1, name:'a', age:10, country:''},{id:2, name:'b', age:14, country:'Malaysia'}]

And I wish to group the values with same key become:

[{id:[1,2], name:['a','b'], age:[10,14], country:['Malaysia']}]

Now I stuck here, I tried .map & .reduce, but not success.

I am thinking to fill first value from each array to my html table if the array key is match with my table td's id. And my key is generate from database, so cannot hardcode inside the code. I will display the key and value in my html table:

<table>
<tr>
<td id='id'>id</td>
<td>1</td>
</tr>
<tr>
<td id='name'>name</td>
<td>a</td>
</tr>
<tr>
<td id='age'>age</td>
<td>10</td>
</tr>
<tr>
<td id='country'>country</td>
<td>Malaysia</td>
</tr>
</table>

Apologize my english is bad

about 4 years ago · Juan Pablo Isaza
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!