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

107
Views
Join every each two array into single element in array

I have array like this

[
  '7 10 8',
  '6 0 0 1 5 1 1 0',
  '7 10 7',
  '1 1 1 1 1 1 1',
  '3 9 7',
  '3 3 3 4 3 3 3'
]

i want to narrow down the element and join every two array

expected output

[
  '7 10 8|6 0 0 1 5 1 1 0',
  '7 10 7|1 1 1 1 1 1 1',  
  '3 9 7|3 3 3 4 3 3 3'
]
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use a simple for loop:

const myArray = [
      '7 10 8',
      '6 0 0 1 5 1 1 0',
      '7 10 7',
      '1 1 1 1 1 1 1',
      '3 9 7',
      '3 3 3 4 3 3 3'
    ];

    const outputArray = [];
    for (let i = 0; i < myArray.length; i = i + 2)
    {
        outputArray.push(myArray[i] + '|' + myArray[i + 1]);
    }

    console.log(outputArray)

In this loop, instead of iterating over every element, you are iterating over every other element, which is why i = i + 2 is used.

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!