1

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>
G. Evens
  • 31
  • 5

1 Answers1

1

Try:

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

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

Rajshekar Reddy
  • 18,647
  • 3
  • 40
  • 59
Arun Ghosh
  • 7,634
  • 1
  • 26
  • 38
  • Thank you it works! Can you tell me what it is the "JSON.stringify"? And how do i get it in a table? – G. Evens Jul 19 '16 at 12:24
  • To put into table ~ you need to iterate through object keys and create table dynamically(you can use jQuery) – Arun Ghosh Jul 19 '16 at 12:28
  • Check this post http://stackoverflow.com/questions/684672/how-do-i-loop-through-or-enumerate-a-javascript-object – Arun Ghosh Jul 19 '16 at 12:48