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

187
Visualizações
Best way Merge two string arrays based on a condition

Hello I want to merge two string arrays.

Array 1:
0: "Cloud Infrastructure"
1: "Cloud Infrastructure"
2: "IaaS"
3: "IaaS"
4: "Infrastructure"
5: "Infrastructure"
6: "Compute"
7: "Compute"
8: "Compute"
9: "Compute"

Array 2:
0: "hideValue123"
1: "hideValue123"
2: "hideValue123"
3: "hideValue123"
4: "hideValue123"
5: "hideValue123"
6: "Networking"
7: "Networking"
8: "Networking"
9: "Networking"

What I want is in the final array. Array three to have all elements of array two that are different from hideValue123. And for those elements that is hideValue123, I want to get them from array 1. I want the order/index to be the same:

Array 3 :
0: "Cloud Infrastructure"
1: "Cloud Infrastructure"
2: "IaaS"
3: "IaaS"
4: "Infrastructure"
5: "Infrastructure"
6: "Networking"
7: "Networking"
8: "Networking"
9: "Networking"
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

const array1 = ["Cloud Infrastructure",
    "Cloud Infrastructure",
    "IaaS",
    "IaaS",
    "Infrastructure",
    "Infrastructure",
    "Compute",
    "Compute",
    "Compute",
    "Compute"]
    
const array2 = [
    "hideValue123",
    "hideValue123",
    "hideValue123",
    "hideValue123",
    "hideValue123",
    "hideValue123",
    "Networking",
    "Networking",
    "Networking",
    "Networking",
]
const array3 = array2.map((item, index) => item === "hideValue123" ? array1[index] : item);
console.log(array3);

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