How to show values of a Javascript Set() in Stackblitz console?

70 Views Asked by At

I've been using stackblitz as a scratchpad for learning and testing javascript. I find it very convenient to use the real time console updates while logging out lines of code.

One problem I've encountered is how the console outputs the results of a Set() method.

For example

let numbers = [1, 1, 2, 2, 3, 3];
numbers = new Set(numbers);
console.log(numbers); // expect: Set(3) {1, 2, 3}

The output of the console.log(numbers) in the chrome inspector is Set(3) {1, 2, 3} However, the output of the stackblitz console is just Set {}

I suppose this is just a quirk of the SB console or is there a workaround that doesn't involve opening the chrome inspector to view the contents of the Set()?

1

There are 1 best solutions below

2
Gershom Maes On

Worst case you can simply do:

console.log([ ...numbers ]);

This will spread numbers into an Array, and the Array will be logged.