Q:

How to turn a string onto a map? 

I need to turn a string formatted like that: 
string = "John:31,Miranda:28"

Onto this;
obj = { "John" => 31, "Miranda" => 28 }
I did this : 
const class = new Map();
array = string.split(",");

And obviously I do not know what do with it because after the split I get something like this:
["John:31", "Miranda:28"]

And I don't know how to turn it onto an object (using the ":" as a arrow)... Maybe I don't need to use the array as an intermediary?  Any thoughts?  Thanks

A:

You can use split to split by comma, and then map on the resulting strings to split again by colon, and feed the resulting array of arrays into the Map constructor. 
For instance, if you want the map keyed by the names, which I suspect you do:

const string = "John:31,Miranda:28"
const map = new Map(string.split(",").map(entry => entry.split(":")));
console.log(map.get("John")); // "31" (a string)

If you want the numbers to be numbers, not strings, you'll need to convert them:

const string = "John:31,Miranda:28"
const map = new Map(string.split(",").map(entry => {
    const parts = entry.split(":");
    parts[1] = +parts[1];
    return parts;
}));
console.log(map.get("John")); // 31 (a number)

My answer here goes into some detail on your options for converting from string to number. 

If you want the map keyed by value instead (which I suspect you don't, but...), you just have to reverse the order of the inner array entries:

const string = "John:31,Miranda:28"
const map = new Map(string.split(",").map(entry => {
    const [name, num] = entry.split(":");
    return [num, name];
}));
console.log(map.get("31")); // John

