Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

265
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda