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

169
Visualizações
Creating an object from two arrays

How to create an object from the below arrays

var v=[1,2,3,4,5,6]

var v1=['A','B','C','D','E']

var result={};

key's for the object are (name & target). I want to map the keys with the above two arrays as value like below

 {name: "1", target: "A"}
 {name: "2", target: "B"}
 {name: "4", target: "C"}

{name: "5", target: "D"} {name: "6", target: "E"}

I was trying with the below logic

v.forEach(key=> result[key]= key);
console.log('ColResult',result);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If the first array consists of increasing numbers equal to the index then there is no need for that array at all...

result = [];
v1.forEach((v, i) => result.push({ name: i, target: v1[i] }));

but in general it should be something like

result = [];
for (var i = 0; i < v.length; i++) {
  result.push({ name: v[i], target: v1[i] });
}
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