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

128
Views
How to create two dimensional array when I have an object in javascript?

I have an object like this:

 const object = {name: ['Jim', 'Jack', 'Betty'],
                 age: [14, 15, 16],
                 gender: ['M', 'M', 'F']}

What I want is to create a text like that:

Jim   14   M
Jack  15   M
Betty 16   F
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Try using map()

const object = {
  name: ['Jim', 'Jack', 'Betty'],
  age: [14, 15, 16],
  gender: ['M', 'M', 'F']
}

const transpose = (arr) => arr[0].map((_, colIndex) => arr.map(row => row[colIndex]));

const transposed = transpose([object.name, object.age, object.gender])

const result = transposed.map(row => row.join('\t')).join('\n')

console.log(result)

about 4 years ago · Juan Pablo Isaza Report

0

If you have a specific properties and have same length, this does the trick:

 const object = {name: ['Jim', 'Jack', 'Betty'],
                 age: [14, 15, 16],
                 gender: ['M', 'M', 'F']}
const [names,ages,genders] = Object.values(object);
const rows = names.map((name, i)=>[name, ages[i], genders[i]]);
const result = rows.map(row => row.join('\t')).join('\n')

console.log(result)

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!