I was trying to convert an object which is used for a map purpose, into a proper Map object. I can iterate over the result of Object.keys()
and do like
var myData = {"key1":1, "key2":2, "key3":3},
myMap = Object.keys(myData).reduce((m,k) => m.set(k,myData[k]) ,new Map());
which does the job. However i gave a try to Object.assign()
like
var myData = {"key1":1, "key2":2, "key3":3},
myMap = Object.assign(new Map(),myData);
which yields a Map with proper key / value pairs yet the size
property always show 0. What's going on here and what would be another nice way to make this conversion that i can not think of..? I am open to any ideas from ES6 and beyond.