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

242
Visualizações
How to merge arrays that derive from the same variable

I have the following line of code which returns me one or more arrays depending on the checkbox that is clicked.

selected.forEach(langsel => {
                let filtered = person.filter(pers => pers.language == langsel);
            })

selected and I do not report the other variables for simplicity in reading.

I have a list of checkboxes where each refers to a particular language. So every time a checkbox is clicked I want the people who speak that language to be returned to me; this must be returned in an array of objects.

catsel refers to the checkbox that is selected (being a checkbox, more than one can also be selected). So for each language that is selected it returns me the array of objects in the filtered variable.

For example, if I select the English language through the checkbox, I get:

[{id: "2", name: "Tomas Addreh", language: "English"},{id: "6", name: "Mark Addreh", language: "English"}];

if together with the checkbox selected previously, therefore English, I also select the checkbox relating to the Spanish language, filtered returns me:

[{id: "2", name: "Tomas Addreh", language: "English"},{id: "6", name: "Mark Addreh", language: "English"}];

[{id: "15", name: "Alex Atres", language: "Spanish"}, {id: "1", name: "Mark Sertoj", language: "Spanish"}, id: "12", name: "Martha Forrest", language: "Spanish"];

filtered in the latter case returns me two separate arrays.

I want them to be merged into an array.

Can anyone kindly help me?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I concat the array by using spread operator.

let people = [];
selected.forEach(langsel => {
    let filteredPerson = person.filter(pers => pers.language == langsel);
    people = [...people, ...filteredPerson];
})
about 4 years ago · Juan Pablo Isaza Relatório
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