Which fix removes the bug?
const scores = new Map([['ana', 3]]);
const body = JSON.stringify(scores);
send(body); // sends "{}"
- Pass a spacer:
JSON.stringify(scores, null, 2) - Spread it first into
{ ...scores } - Convert first:
Object.fromEntries(scores) - Send
scores.toString()as the body
A Map has no enumerable own properties, so JSON sees an empty object; convert it to a plain object first.
Play Problem Solving ▸