Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the entries (), keys () and values () methods in ES6

Shulou Source: shulou.com Published: 2022-06-01 03:46:49 10月03日 Update

This article mainly shows you "how to use entries (), keys () and values () methods in ES6". The content is simple and clear. I hope it can help you solve your doubts. Let the editor lead you to study and learn how to use the methods of entries (), keys () and values () in ES6.

Entries (), keys () and values ()

ES6 provides three new methods-- entries (), keys (), and values ()-- for traversing arrays. They all return a traversal object that can be traversed with a for...of loop, except that keys () is the traversal of the key name, values () is the traversal of the key value, and entries () is the traversal of the key-value pair.

For (let index of ['asides,' b'] .keys ()) {console.log (index);} / 0 / / 1 for (let elem of ['asides,' b'] .values ()) {console.log (elem);} / /'a' / /'b' for (let [index, elem] of ['asides,' b'] .values ()) {console.log (index, elem) } / / 0 "a" / / 1 "b"

If you do not use a for...of loop, you can manually call the next method of the traversal object to traverse.

Let letter = ['averse,' baked,'c']; let entries = letter.entries (); console.log (entries.next () .value); / / [0,'a'] console.log (entries.next () .value); / / [1,'b'] console.log (entries.next () .value) / / [2,'c'] these are all the contents of this article entitled "how to use the entries (), keys () and values () methods in ES6". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Method content article object learning help loop three manual array easy to understand more organization knowledge editing industry information information channel channel research Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Xiaomi Redmi Docker NVidia