12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <!--<script src="index.js"></script>-->
- <script>
- {
- const persons = [
- {
- "Name":"chevrolet chevelle malibu",
- "Cylinders":8,
- "Displacement":307,
- "Horsepower":130,
- "Weight_in_lbs":3504,
- "Origin":"USA"
- },
- {
- "Name":"buick skylark 320",
- "Miles_per_Gallon":15,
- "Cylinders":8,
- "Displacement":350,
- "Horsepower":165,
- "Weight_in_lbs":3693,
- "Acceleration":11.5,
- "Year":"1970-01-01",
- },
- {
- "Miles_per_Gallon":18,
- "Cylinders":8,
- "Displacement":318,
- "Horsepower":150,
- "Weight_in_lbs":3436,
- "Year":"1970-01-01",
- "Origin":"USA"
- },
- {
- "Name":"amc rebel sst",
- "Miles_per_Gallon":16,
- "Cylinders":8,
- "Displacement":304,
- "Horsepower":150,
- "Year":"1970-01-01",
- "Origin":"USA"
- },
- ]
- let arrColumn = [];
- for ( let obj of persons){
- for (let key in obj ){
- if ( !(arrColumn.includes(key)) ) {arrColumn.push(key)}
- }
- }
- let table = '<table>';
-
- table += '<tr>'
- for (let th of arrColumn){
- table += '<th>' + th + '</th>'
- }
- table += '</tr>'
- for ( let obj of persons) {
- table += '<tr>';
- for (column of arrColumn){
- table += '<td>'
- if (obj[column]) { table += obj[column] }
- table += '</td>'
- }
- table += '</tr>';
- }
- table += '</table>'
- document.write(table)
- }
- </script>
- </head>
- <body>
-
- </body>
- </html>
|