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

229
Views
Create a table with keys and values from JS map

I'm trying to create a table with all its information from a javascript map (it's for a school project, if you're wondering why I have to use map). This feels like it shouldn't be a problem but my brain refuses to cooperate.

        var volkswagen = {
            name: "Volkswagen",
            country: "Germany",
            revenue: 260000000000
        };

        var toyota = {
            name: "Toyota",
            country: "Japan",
            revenue: 256000000000
        };

        var mercedes = {
            name: "Mercedes",
            country: "Germany",
            revenue: 187000000000
        };

        var brands = new Map();
        brands.set(volkswagen.name, volkswagen);
        brands.set(toyota.name, toyota);
        brands.set(mercedes.name, mercedes);

How would one go about doing this?

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

0

if i undrastend you want to fill brands table with objects so try this :

var brands = []
brands.push(volkswagen)
brands.push(toyota)
etc...
 or 
var brands = [volkswagen,toyota etc...]
about 4 years ago · Juan Pablo Isaza Report

0

There are many possible ways of compiling a table out of the data you provided, the following is one of them:

var volkswagen = {
  name: "Volkswagen",
  country: "Germany",
  revenue: 260000000000
};

var toyota = {
  name: "Toyota",
  country: "Japan",
  revenue: 256000000000
};

var mercedes = {
  name: "Mercedes",
  country: "Germany",
  revenue: 187000000000
};

document.body.innerHTML=
`<table><tr><th>${Object.keys(toyota).join("</th><th>")}</th></tr>
${[volkswagen,toyota,mercedes].map(o=>
    "<tr><td>"+Object.values(o).join("</td><td>")+"</tr>").join("\n")}</table>`
td,th {border:1px solid grey}

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!