entries() - JavaScript Array Methods

Опубликовано: 12 Январь 2020
на канале: Mackley Studios
204
4

entries() returns an iterator object that is used to step through each item in the array. Object also has an entries() method that can be iterated through with a for ... of loop. With Object, this is very useful because it gives us access to both the key and the value as we're looping over the entries of an object. With Array, the key is always the index of the array, and could be accessed with a regular for loop. The fact that entries() is also available on Array, however, provides some uniformity in the language. But much more than that, there are unique use cases for iterators. Iterators consume memory only as needed. Think of them as a method for control flow. Unlike arrays, iterators do not have the static concept of length. Instead, each time an iterator runs, it calls next() until its value for done is true. A regular for loop needs to load the entire collection into memory in order to iterate over it, whereas an iterator only needs to know the current position in the collection, meaning we can stop it and start it and control when we want to move onto processing the next element. This has the ability to make processing our code more efficient on large collections. Keep this in mind if you have a large - and potentially slow - array list that you need to process in a loop. The concept is, in many ways, similar to streaming or pagination: it's much easier to consume a lot of data in small bites, as needed, instead of all at once.

Visit the website you can read more articles, find more videos, and sign up to the newsletter.
https://mackleystudios.com/

Looking for a remote freelancer?
Send me an email at contact@mackleystudios.com


На этой странице сайта вы можете посмотреть видео онлайн entries() - JavaScript Array Methods длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Mackley Studios 12 Январь 2020, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 204 раз и оно понравилось 4 зрителям. Приятного просмотра!