How to use the entries (), keys () and values () methods in ES6
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!