G. Evens G. Evens - 4 months ago 13
Javascript Question

Print Out Jquery object to table

I got a script that count all

td
with the same value's in my table. The output is just what i need.

But it goes wrong when i want to print the data to html. When i do
console.log
i get

Object {EANDIS - RC GROND 2014-2018: 11, ASWEBO - FARYS: 7, VDV CLEANING - RIOOLKOLKENSLIB: 1}


I have tried to print it out with:
document.getElementById("write").innerHTML = byTechnology;
But the output is Objectobject.

What am i doing wrong? Or is their another way to do it?

Here you will find the script. I hope you can help me!

<script>
var byTechnology = {};

$("#test tbody td:nth-child(6)").each(function() {
var tech = $.trim($(this).text());

if (!(byTechnology.hasOwnProperty(tech))) {
byTechnology[tech] = 0;
}

byTechnology[tech]++;
});

console.log(byTechnology);
document.getElementById("test").innerHTML = byTechnology;
</script>

Answer

Try:

document.getElementById("write").innerHTML = JSON.stringify(byTechnology);

The JSON.stringify() method converts a JavaScript object to a JSON string.

Comments