What is the traversal method of map object in es6
Most people do not understand the knowledge points of this article, "what is the traversal method of map objects in es6?" so the editor summarizes the following, detailed contents, clear steps, and a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the traversal method of map objects in es6".
Map traversal methods are: 1, with forEach () function, syntax "map.forEach (function (value,key) {...}"; 2, using "for..of" loop statement, syntax "for ([key, value] of map object) {...}".
The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.
Map is the structure of a set of key-value pairs with extremely fast search speed. Created by passing in an array of arrays.
Traversal method of Map object
ForEach ()
For..of traverses keys, values, entries
Iterator.next () traverses keys, values, entries
1. ForEach () function
Var map = [{key: "Baidu", value: "Robin Li"}, {key: "Alibaba", value: "Jack Ma"},]; map.forEach (function (value, key) {console.log (key, value);})
2. For..of cycle
Keys = map.keys (); for (key of keys) {console.log (key); / / map.get (key) can get the value. } values = map.values (); for (value of values) {console.log (value);} entries = map.entries (); for ([key, value] of entries) {console.log (key, value);}
The above is the content of this article on "what is the traversal method of map objects in es6". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.