Let's say I have a Map:
const m = new Map([[1,1], [2,2], [3,3]]);
What's the quickest method to inline it in template literal in a manner that it will look like this:
or any other readable format?
P.S. This won't work:
const str = `${m}`;
You could take a function for it, which takes the map and creates a string.
function beautify(o) {
if (o instanceof Map) {
return 'Map(' + JSON.stringify(Array.from(o.entries())) + ')';
}
return o;
}
const m = new Map([[1,1], [2,2], [3,3]]);
console.log(beautify(m));