课程: JavaScript: Maps and Sets

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Iterate over a set with entries

Iterate over a set with entries

- [Instructor] The next method we will discuss is entries. And it's another set method that returns an iterator. As we have learned, our set just contains values unlike map, which contains keys and values. And this entries method will return an array that contains the value twice. You may be wondering why the value is returned twice? And the reason is that it was done in order to keep the API similar to map. This is an interesting value to work with and you may find that it's not something you'll reach for very often, but it's still important to learn about how this method works. Just like the values method we will iterate over the available entries by using the next method, and then applying value. If we take a look at our invites example, we can see that this follows a very similar pattern and usage to the values method. We start by creating a new variable invite entries and set that equal to the invites with the…

内容