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

116
Visualizações
Creating unique set from array of objects and assigning all object's data to a specific container

I am working with Firestore and here is a problem I'm having.

I created a collection of docs and it's structure is like this:

const myArr = [
    {title: 'title 1',name: '10 name',age: 10},
    {title: 'title 2',name: '20 name',age: 20},
    {title: 'title 2',name: '21 name',age: 20},
    {title: 'title 2',name: '22 name',age: 20},
    {title: 'title 3',name: '30 name',age: 30}
]

I needed all unique titles so I created a set:

const unique = [...new Set(myArr.map(item => item.title))];

I added them to my dom so that each unique title would be a heading:

let wrapper = document.querySelector('#main');

for(let i = 0; i < unique.length; i++) {
    let myDiv = document.createElement('div');
    myDiv.className = 'unique_list';
    wrapper.appendChild(myDiv);
    myDiv.innerHTML = `<h3 data-title="${unique[i]}">${unique[i]}</h3><br><br>`;
}

Now I need to add to every "unique_list" div also all objects that are the same as this unique title so that each container would look somewhat like this:

<div class="unique_list" data-title="title 2">
    <h3>title 2</h3>
    <div>
        <p>name: 20 name</p>
        <p>age: 20</p>
    </div>
    <div>
        <p>name: 21 name</p>
        <p>age: 20</p>
    </div>
    <div>
        <p>name: 22 name</p>
        <p>age: 20</p>
    </div>
</div>

Currently I am stuck with nested for loops and no idea how to achieve this, I would much appreciate any suggestions, thanks.

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