I just get using Map data structure and I am trying to accomplish the opposite of what is showed on those answers:
How to convert Map keys to array?
Indeed I want achieve same as asked here but the answered proposed does not work:
Indeed:
let answers = [1,"2",3];
let myMap = new Map();
myMap.set('0', 'foo');
myMap.set(1, 'bar');
myMap.set({}, 'baz');
myMap.set(answers);
So I would like to get as result:
myMap = ( [1, 'foo'],["2",'bar'],[3,'baz'])
but the new array is just "appended" at the end of the Map as from the https://jsfiddle.net/CarmineT/5m02exn8/, instead I want to substitute each keys( with which rule I don't mind ), so I tried iterate through the iterable ( Map ) such
let k = myMap.keys();
for (let [key, value] of iterable) {
k.next().value = answers
}
or with a more elegant way, maybe a forEach, but first I would like to understand where I am mistake here as it does not work.
On the similar question, an answer does mention about a library that use the concept of Tree, but I would avoid to use an external library if possible.