Set/Map logged as empty object in editor output
See original GitHub issueAffected page
Javascript Code Editor
To reproduce
Steps to reproduce the behavior:
- Write the following code;
const test = new Set([1,2,3,4,5]);
console.log("Output:", test);
Expected behavior
Output: Set(5) { 1, 2, 3, 4, 5 }
Screenshots
System
- Device: Laptop
- OS: Windows 10
- Browser: Edge
- Version: 96.0.1054.34
Additional context
https://forum.freecodecamp.org/t/javascript-sets-not-logging-on-freecodecamp-editor/486895
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Javascript Sets not logging on freeCodeCamp editor
Jus try this code in the editor: const test = new Set([1,2,3,4,5]) console.log(test); ... Set/Map logged as empty object in editor output.
Read more >how to display empty game object in the editor? - Unity Answers
I use empty game objects as reference points, but I find it really hard to position them in the editor because they are...
Read more >Map & Set • Angular - codecraft.tv
Map is a new data structure introduced in ES6 which lets you map keys to values without the drawbacks of using Objects.
Read more >How can I Display a JavaScript ES6 Map Object to Console?
The results are always empty object. When I use console.log([...mapObject]);. It prints out an array format.
Read more >Map Class | Apex Reference Guide - Salesforce Developers
Uniqueness of keys of all other non-primitive types, such as sObject keys, is determined by comparing the objects' field values. Map keys of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I dug into this a little bit: the problem is that https://github.com/freeCodeCamp/freeCodeCamp/blob/main/client/src/utils/format.js relies on a fallback https://github.com/browserify/node-util when running in the browser. This fallback does not know how to handle sets or maps and just returns
{}
.If anyone wants to work on this, the obvious approach is to check if the input is an
instanceof
Set
orMap
and then write some custom code to format them.I take it we are leaving this open, as tests should probably be added?