0

The output of following js script doesn't print toString() version of object if it has more than 2 elements.

let printMe_1 = [{
    "A": "a",
    "F": {
        "J": "j",
        "K": "k",
        "L" : "l"
    },
    "G": {
        "J": "j",
        "K": "k",
    }
}]

console.table(printMe_1);

Console output:

enter image description here

And here is the reference to documentation: https://developer.mozilla.org/en-US/docs/Web/API/Console/table

Maas
  • 1,317
  • 9
  • 20
  • 1
    Funny enough in reviewing the specifications for this it looks like there are none. `TODO: This will need a good algorithm.` https://console.spec.whatwg.org/#table Mozilla doesn't define behavior for this either https://developer.mozilla.org/en-US/docs/Web/API/Console/table so seems its just up to the browser implementation currently. – asawyer Oct 02 '20 at 20:33
  • You could try `JSON.stringify()` or [`console.dir` with depth option](https://stackoverflow.com/questions/10729276/how-can-i-get-the-full-object-in-node-jss-console-log-rather-than-object) – SNag Oct 02 '20 at 20:36
  • @asawyer exactly! I did look up for it too! I didn't add it in my question because I hope some one is better than me at googling :) – Maas Oct 02 '20 at 20:38
  • @SNag yes I did, but it does give the table output and stringfy() makes me loose the dynamic nature of object – Maas Oct 02 '20 at 20:40

1 Answers1

0

Your code works fine in Firefox 81.0 browser console. All levels of F show up.

console.table Firefox 81.0

In Chrome 85.0 and in Edge Chromium 85.0 the table doesn't list the entries but the object gets printed separately anyway.

console.table Chrome 85.0 / Edge Chromium 85.0

Node 14.5 doesn't print it, as you've rightfully captured.

console.table Node 14.5

As per @asawyer's comment it seems this is left to the browser's/Node's implementation.

Alternatively, you can try JSON.stringify() or console.dir with depth option.

SNag
  • 17,681
  • 10
  • 54
  • 69