0

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()?

js-newb
  • 421
  • 6
  • 16

1 Answers1

1

Worst case you can simply do:

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

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

Gershom Maes
  • 7,358
  • 2
  • 35
  • 55
  • Thanks. I should have mentioned in my question that I've essentially been doing what you propose. Just asking if perhaps I'm missing something or does SB just have a limitation that other online editors (jsfiddle, codepen, etc) do not appear to have. I much prefer SB but for this one quirk. – js-newb Jun 29 '23 at 18:30
  • Sounds like an idiosyncrasy of stackblitz's `console.log` implementation to me... – Gershom Maes Jun 29 '23 at 20:57