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

134
Views
How to arrange/edit multiple arrays | Javascript

I have three sets of data

var item = ['item1', 'item2', 'item3', ...]
var price = ['price1', 'price2', 'price3', ...]
var date = ['date1', 'date2', 'date3', ...]

Is there any way that I can arrange this into a specific order like

[
    ['item1', 'price1', 'date1'],
    ['item2', 'price2', 'date2'],
    ['item3', 'price3', 'date3'],
    .....
]

Thanks in advance.

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

0

You can try with for loop or map function

const item = ['item1', 'item2', 'item3'];
const price = ['price1', 'price2', 'price3'];
const date = ['date1', 'date2', 'date3'];

const result = item.map((v, i) => [v, price[i], date[i]]);
about 4 years ago · Juan Pablo Isaza Report

0

I assume your data is sorted as intended, even the length of different array is not the same the code below should work

const arranged = []
const length  = Math.min(item.length, price.length, date.length)
for (let index = 0; index < length; ++index){
    arranged.push([item[index], price[index], date[index]])
}

console.log(arranged)
about 4 years ago · Juan Pablo Isaza Report

0

Given that your arrays are all in the same length, below is a short way that you could achieve your expected result

var item = ['item1', 'item2', 'item3']
var price = ['price1', 'price2', 'price3']
var date = ['date1', 'date2', 'date3']

const res = Array.from({
  length: item.length
}, (_, i) => [item[i], price[i], date[i]])

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!