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

138
Views
How to Perform 2 join operation on an Object array?
const rows = [
    ["Name", "City", "Info"],
    ["name1", "city1", "some other info"],
    ["name2", "city2", "more info"]
];
let csvContent = rows.map(e => e.join(",")).join("\n");

Similarly how can I implement the same on an Object array for example

const rows = [
        {name:"FirstName", city:"City", info:"Info"},
        {name:"LastName", city:"City", info:"Info"},
    ];
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

First you can Array#reduce it, saving the Object.keys as the first header row, then creating the array structure. Finally map all that just like your first example.

const rows2 = [{
    name: "FirstName",
    city: "City",
    info: "Info"
  },
  {
    name: "LastName",
    city: "City",
    info: "Info"
  },
];

let csvContent2 = rows2.reduce((b, a, i) => {
  if (i === 0) b.push(Object.keys(a))
  return b.concat([Object.values(a)]);
}, []).map(e => e.join(",")).join("\n")
console.log(csvContent2);

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!