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

202
Views
How to fill the missing values in an array with another array

How to fill the missing values in the array1

array1 = [1,'',12,23,'',5]

basically, they are 3 values but only 2 values can be placed

array2 = [6,8,9]

sample output

array1 = [1,6,12,23,8,5]
array2 = [9]
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Start with something like this.

array1 = [1,'',12,23,'',5]
array2 = [6,8,9]
array1 = array1.map(val => val === '' ? array2.shift() : val);

Or

for (let i = 0; i < array1.length; i++) {
  if (array1[i] === '') array1[i] = array2.shift();
}

Read about https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/shift. Have fun!

about 4 years ago · Juan Pablo Isaza Report

0

let array1 = [1,'',12,23,'',5]
let array2 = [6,8,9]
for (var i = 0; i < array1.length; i++) {
    if(array1[i]=== ''){
        console.log(array1[i])
         array1[i] = array2.shift()
    }
}
about 4 years ago · Juan Pablo Isaza Report

0

let array1 = [1,'',12,23,'',5];
const array2 = [6,8,9];

array1 = array1.map((item) => {
    if (Boolean(item)) {
        return item
    } else {
        return array2.shift();
    }
});

console.log(array1);
console.log(array2);

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!