@randomwizard@social.vivaldi.net
Post #2933574
2026-05-21 20:57 UTC
//javascript is cursed
someVar = new Map();
someVar.name = "Bob";
someVar.age = 24;
console.log(JSON.stringify(someVar));
//OUTPUT IS...
/*
{"name":"Bob","age":24}
*/
console.log(someVar.get("name"));
//OUTPUT IS...
/*
undefined
*/
someVar.set("name", "Maxwell");
someVar.set("age", 64);
console.log(JSON.stringify(someVar));
//OUTPUT IS...
/*
{"name":"Bob","age":24}
*/
for (const [key, value] of Object.entries(someVar)) {
console.log(key, value);
}
//OUTPUT IS...
/*
name Bob
age 24
*/
for (const [key, value] of someVar) {
console.log(key, value);
}
//OUTPUT IS..
/*
name Maxwell
age 64
*/
const nextVar = new Map();
nextVar.set("name", "Jane");
nextVar.set("age", 21);
console.log(JSON.stringify(nextVar))
//OUTPUT IS...
/*
{}
*/
console.log(JSON.stringify(Object.fromEntries(nextVar)));
//OUTPUT IS
/*
{"name":"Jane","age":21}
*/
Replies (0)
No replies.