How to adress objects and its items in a nested map. My code looks like this:
using the old syntax for console.log - console.log(“mapGame”, mapGame) - shows all the maps content, but using the template literal syntax shows only that it is a an object.
As you can see I can only get the key??? - Thanks in advance.
/* ************* GAME OBJECT *******************/
const gameObject = {};
function gameObjectCreate() {
spilNr += 1;
objId = String(`${dato}-${spilNr}`);
gameObject.spilNr = spilNr;
//gameObject.deltagere = obj;
gameObject.deltagere = {
Kim: true,
Ole: true,
Preben: true,
Henrik: true,
Lars: true,
flemming: true,
};
/* ************* GAME MAP OBJECT *******************/
const mapGame = new Map();
mapGame.set(objId, gameObject);
console.log("mapGame", mapGame);
console.log(`mapGame, ${mapGame}`);
console.log("deltagere:", mapGame.get(objId).gameObject);
let textKey = "";
for (const x of mapGame.keys()) {
textKey += x;
}
let textValue = "";
for (const y of mapGame.values()) {
textValue += y;
}
console.log(
`key = ${textKey} \nvalue = ${textValue}\nmapGame.deltagere = ${mapGame.get(
objId
)}`
);
}
****************** CONSOLE LOG ************************
mapGame Map(1) {‘17.11.2022-1’ => {…}}
[[Entries]]
0: {“17.11.2022-1” => Object}
key: “17.11.2022-1”
value: deltagere: {Kim: true, Ole: true, Preben: true, Henrik: true, Lars: true, …}
spilNr: 1
[[Prototype]]: Objectsize: 1
[[Prototype]]: Map
mapGame, [object Map]
deltagere: undefined
key = 17.11.2022-1
value = [object Object]
mapGame.deltagere = [object Object]