Home >Web Front-end >Front-end Q&A >What is the difference between es6 map objects and native objects?
Difference: 1. The type of the key in the native object object's key-value pair combination is string, and the map object's key-value pair storage type can be any type; 2. The native object object uses the key-value combination "Object.keys" returns an array, while the map object uses "map variable.keys()".
The operating environment of this tutorial: Windows 10 system, ECMAScript version 6.0, Dell G3 computer.
Difference
Object and Map store both key-value pair combinations. However: the key type of
object is a string; the key type of
map can be any type;
Also note that
object obtains key values using Object.keys (returns array);
Map obtains Key values use map variable.keys() (returns iterator).
Sample code:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>js es6 map 与 原生对象区别</title> </head> <body> <script type="text/javascript"> let a = { o: 1 }; // string console.log(typeof Object.keys(a)[0]); let map = new Map(); map.set(a, 'content'); // 输出是object 也可以是任何类型 console.log(map.keys().next()); </script> </body> </html>
[Related recommendations: javascript video tutorial, web front-end]
The above is the detailed content of What is the difference between es6 map objects and native objects?. For more information, please follow other related articles on the PHP Chinese website!