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

127
Views
Merge array into a new array javascript in a loop

Hi all i have this loop which will loop 4 times.

for (var i = 0; i < 4; i++){
  var d = [[1111,2222],[3333,4444]]
}

below is my expect output , thank you every much all.

var expected = [ 
 [
   [1111,2222],[3333,4444]
 ], 
 [
   [1111,2222],[3333,4444]
 ], 
 [
   [1111,2222],[3333,4444]
 ], 
 [
   [1111,2222],[3333,4444]
 ]
]
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Is that what you tried to achieve?

const output = [];
const input = [[1111,2222],[3333,4444]]
for (var i = 0; i < 4; i++){
  output.push(input)
}
console.log(output) // [[[1111,2222],[3333,4444]], [[1111,2222],[3333,4444]], [[1111,2222],[3333,4444]], [[1111,2222],[3333,4444]]]
about 4 years ago · Juan Pablo Isaza Report

0

You can get the result like this

    function getNewArray() {
        var newArray = []
        for (var i = 0; i < 4; i++){
            var d = [[1111,2222],[3333,4444]]
            newArray.push(d)
        }
        return newArray;
    }
    
    let expected = getNewArray()
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!