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

127
Visualizações
use array of indexes to filter another array javascript

I have 1 array and 1 set,set Indexes and array is Names.

Indexes contains various numbers which are basically indexes of random elements of Names array.I want to filter Names array based on indexes in Indexes array i.e push specific elements of Names array to another array whose indexes are present in the Indexes array.

What I am doing is:

const Indexes =[0,1]
const Names=["Test1","Test2","Test3","Test4"]

const filteredNames = Indexes.map(item => Names[item]);

Output should be:

filteredNames=["Test1","Test2"]

but its not working.Any leads on this?

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

0

If Indexes is a Set, then you just need Array.from function:

const Indexes =new Set([0,1])
const Names=["Test1","Test2","Test3","Test4"]

const filteredNames = Array.from(Indexes)
    .map(item => Names[item]);
about 4 years ago · Juan Pablo Isaza Relatório

0

You almost had it right

const Indexes =[0,1]
const Names=["Test1","Test2","Test3","Test4"]

const filteredNames = Indexes.map(item => Names[item]);
console.log(filteredNames)

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