![]() ![]() Īs mentioned, this are all optional, but they all provide a useful way to manipulate and calculate the return value for your reduce method. If provided, this will be the previousElement for index. This will return the entire array - which can be useful if you plan to manipulate the array using reduce, or, if you want to compute based on other elements in the array Expect standard array indexes from this argument. This will return the 0 indexed number representing the current element's position in the array. Since arrays don't consist of just indexes, and often have useful data in them, we also have the ability to get the current index being iterated through. This is the current element that is being iterated through by reduce. If you have defined an initialValue, then this value will be used and the reduce function will begin at index, using the initialValue as the previousValue. The reduce function will usually start at the index, so that a previous element does exist. It represents the previous element from the current one we are iterating through. Let's look at what previousElement, currentElement, currentIndex, array and initialValue all mean. Enter fullscreen mode Exit fullscreen mode ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |