JS: Convert Object to Map ð
Convert Object to Map (require JS2017)
/* xah_obj_to_map(obj) convert obj to map datatype. Return a map instance. The input obj is not changed. Only keys converted are: own property, enumerable, string keys. Require JS2017 Version 2018-02-02 */ const xah_obj_to_map = (obj) => (new Map(Object.entries(obj))); // HHHH--------------------------------------------------- // test const xx = { "a": 2, "b": 9, [Symbol()]: "symbol" }; console.log(xah_obj_to_map(xx)); // Map { "a" => 2, "b" => 9 }
Convert Object to Map (no require JS2015)
Here is a function that converts object to map data type.
/* xah_obj_to_map(obj) convert obj to map datatype. Return a map instance. The input obj is not changed. Only keys converted are: own property, enumerable, string keys. Version 2018-02-02 */ const xah_obj_to_map = ((obj) => { const mp = new Map(); Object.keys(obj).forEach((k) => { mp.set(k, obj[k]); }); return mp; }); // ssss--------------------------------------------------- // test const xx = { "a": 2, "b": 9, [Symbol()]: "symbol" }; console.log(xah_obj_to_map(xx)); // Map { "a" => 2, "b" => 9 }
JavaScript, Map Object
- JS: Map Object Tutorial
- JS: Difference, Object vs Map
- JS: Literal Expression for Map
- JS: Nested Map
- JS: Iterate Map Object
- JS: Convert Object to Map ð
- JS: Convert Map to Object ð
- JS: Map Equality ð
- JS: Map Filter ð
- JS: Swap Key Value of Map ð
- JS: Sort Map ð
- JS: Truncate Map ð
- JS: Map Substract ð
- JS: How Map Determines Uniqueness of Keys
- JS: Map Object
- JS: Map Constructor
- JS: Map.prototype