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

77
Views
Replace element from first array by another element of second array

I am having this issue replacing element from first array by another element of second array.

For exapmle if I have one array haiving some empty values and string like this:

let array_1 = [empty, 'Connected', empty, 'Connected', 'Connected'];

And another new array will be like this:

let array_2 = [empty, 'Updated'];

So, New updated array with replaced element will look like this:

newArray = [empty, 'Updated', empty, 'Connected', 'Connected'];

I tried with for loop and by using findIndexof, but could not replace the element with exact index address.

One of them which worked for me partially is:

console.log(Object.values(...array_1, ...array_2));

Out of above line is just one array with one element, not reast of element from array_1:

['Updated']

But it seems like Obejct.values() does not work with element generated as a empty.

Any possible solution on this would be great!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If I understood it properly you can solve it by using map function like this:

let array_1 = [undefined, "Connected", undefined, "Connected", "Connected"];
let array_2 = [undefined, "Updated"];

const res = array_1.map((val, idx) => {
  return array_2[idx] || val;
});
console.log(res);

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!