![]() Notice how the first iteration has a total of 13 and the number is 2. This is pretty hard to explain in just english so lets look at a code example where we try to get the total price of a list of items. The first parameter is the accumulator which is the thing you are reducing your array down to, and the second parameter is the current element in the array. The reducer function takes two parameters. The first parameter is a function, generally called the reducer, that will be called on each value in the array and the second parameter is the starting value that will be used in your reducer function. The reduce method in its simplest form takes two parameters. This value could be anything such as a number, object, or string. The reduce method is actually named pretty well since all it does is take an array of elements and reduce that array down to one single value. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |