英文:
How to show values of a Javascript Set() in Stackblitz console?
问题
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 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()?
英文:
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
得分: 1
最糟糕的情况下,你可以简单地执行:
console.log([ ...numbers ]);
这将把 numbers
展开到一个数组中,然后打印出这个数组。
英文:
Worst case you can simply do:
console.log([ ...numbers ]);
This will spread numbers
into an Array, and the Array will be logged.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论