Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the traversal method of map object in es6

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report