Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!