Home>Article>Web Front-end> What are the traversal methods of es6 map objects?
The map traversal methods are: 1. Use the forEach() function, the syntax "map.forEach(function(value,key){...}"; 2. Use the "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 a structure of key-value pairs, with extremely fast search speed. It is created by passing in an array of arrays.
##Map object The traversal method
var map = [{ key : "百度", value : "李彦宏" }, { key : "阿里巴巴", value : "马云" }, ]; map.forEach(function(value, key) { console.log(key, value); })
2. for..of loop
keys = map.keys(); for (key of keys) { console.log(key); // map.get(key)可得value值。 } values = map.values(); for (value of values) { console.log(value); } entries = map.entries(); for ([key, value] of entries) { console.log(key, value); }
##[Related recommendations:
javascript video tutorial、webfrontend
】The above is the detailed content of What are the traversal methods of es6 map objects?. For more information, please follow other related articles on the PHP Chinese website!