I started learning JS, especially Node.js, around 5-6 months ago, I worked a lot with Discord.js library and have knowledge of other programming languages.
I want to create a kind of datastore using Map(), before I only created arrays of objects, Discord.js had a bunch of maps in use and it was a pleasure to use them.
My new goal is to create a little app using Electron, I need to save users and program lists in maps, for persistence I want to save them as JSON, if it's possible, here are some example data from my pre-created JSON user file:
"user": [
{
"name": "David",
"currentProgram": "program1",
"currentPhase": "C",
"workout": [
{
"name": "Workoutname",
"load": "10",
"units": "kg"
}
]
},
{
"name": "Markus",
"currentProgram": "program2",
"currentPhase": "A",
"workout": []
}
]
program file:
"program": [
{
"name": "program1",
"phases": [
{
"name": "A",
"cycles": [
{
"name": "day 1",
"exercises": [
{
"name": "workout1",
"set": 4,
"repetitions": 8
},
{
"name": "workout2",
"set": 4,
"repetitions": 8
}
]
}
]
}
]
}
]
My goal is to do something like this:
var user = require('./user.json');
user.get("David").currentProgram = "program2";
user.get("David").currentPhase = "A";
var phase = program.get("program1").phases.get("A")
console.log(user.get("David"));
Instead of using an array like shown in the JSON file, I would create a Map().
I was searching for some information how to create a map the best way in my case. If anyone has good how to's for learning js, especially Map() I would appreciate that. The only thing I found is array.map or google maps but that differs from Map().
Another goal is the separate the code into different files so that I have a sperate file with the construction of each map.
Thanks a lot!