Home > Net >  How to show array content in output window?
How to show array content in output window?

Time:05-10

I'm getting some info from a URL working in javascript in Chrome console.

From a previous code I get an array content with html code as below.

const arrTable = [
                    "<html>",
                    "<table>",
                    "<tr>",
                    "<th>Company</th>",
                    "<th>Contact</th>",
                    "<th>Country</th>",
                    "</tr>",
                    "<tr>",
                    "<td>Alfreds Futterkiste</td>",
                    "<td>Maria Anders</td>",
                    "<td>Germany</td>",
                    "</tr>",
                    "<tr>",
                    "<td>Ernst Handel</td>",
                    "<td>Roland Mendel</td>",
                    "<td>Austria</td>",
                    "</tr>",
                    "</table>",
                    "</html>"
        ]

My goal is to paste it the array content (the table) in MS Excel in order MS Excel interprets it as a table directly without any other manipulation.

I've tried rigth click over arrTable and Copy Object then I paste it in notepad but the text contains the double quotes, commas, square brackets, etc. and I need to clean manually that text to have a valid HTML and be able to paste in Excel.

enter image description here

Is there a way in javascript to show the array content within a temporary output box (like a pop up window) in Chrome? In that way I would be able to copy the output box text and paste it in Excel. Thanks for any help

CodePudding user response:

In case you are specifically looking for a pop-up in Chrome, something like this might help:

alert(arrTable.join(''))

Working snippet:

const arrTable = [
  "<html>",
  "<table>",
  "<tr>",
  "<th>Company</th>",
  "<th>Contact</th>",
  "<th>Country</th>",
  "</tr>",
  "<tr>",
  "<td>Alfreds Futterkiste</td>",
  "<td>Maria Anders</td>",
  "<td>Germany</td>",
  "</tr>",
  "<tr>",
  "<td>Ernst Handel</td>",
  "<td>Roland Mendel</td>",
  "<td>Austria</td>",
  "</tr>",
  "</table>",
  "</html>"
]

alert(arrTable.join(''))

CodePudding user response:

Simply use:

console.log(arrTable.join(""));

then right click in the browser console and select: Copy string contents

then paste in Excel.

Paste HTML table in excel

  • Related