Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4619890
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:29:09+00:00 2026-05-22T02:29:09+00:00

i have C++ program exporting log files as HTML table and I wanted to

  • 0

i have C++ program exporting log files as HTML table and I wanted to know if there is any way that i can parse that table(something like this):

<table>
<tr><td>id</td><td>value1</td><td>value2</td></tr>
<tr><td>0 </td><td>0     </td><td>0     </td></tr>
<tr><td>0 </td><td>1.5   </td><td>2.15  </td></tr>
</table>

into a JSON array (something like this) using a Javascript function:

 var chartData = [
            {id:"0",value1:"0",value2:"0"},
            {id:"1",value1:"1.5",value2:"2.15"}];

The problem is that I want this function to work for every table given to it, with any possible row or column count(first row is always a header).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T02:29:09+00:00Added an answer on May 22, 2026 at 2:29 am

    Here’s my implementation:

    var tableToObj = function( table ) {
        var trs = table.rows,
            trl = trs.length,
            i = 0,
            j = 0,
            keys = [],
            obj, ret = [];
    
        for (; i < trl; i++) {
            if (i == 0) {
                for (; j < trs[i].children.length; j++) {
                    keys.push(trs[i].children[j].innerHTML);
                }
            } else {
                obj = {};
                for (j = 0; j < trs[i].children.length; j++) {
                    obj[keys[j]] = trs[i].children[j].innerHTML;
                }
                ret.push(obj);
            }
        }
    
        return ret;
    };
    

    Which you would invoke like:

    var obj = tableToObj( document.getElementsByTagName('table')[0] ); // or
    var obj = tableToObj( document.getElementById('myTable') );
    

    See working example →

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the below code where I am expecting that when the user will
I have an application that I am working on modifying and I am having
I have to find a way to display the Maximum and Minium number in
This simple program starts with 15 threads - according to the count. Sometimes during
I am using Eclipse as a Python IDE. Is there anyway for me to
In the following code, I'm implementing an interface, and then deriving from that class
I'm trying to implement Tasks in my Application. Here's the sample code: There's one
All, I am trying to inject a long text entry into a SQLite database,
I made a cross compiling toolchain for arm-gcc, configuring binutils, newlib, gcc and gdb
Problem with % n * %n in writable segment detected * C++ i Qt

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.