For of loop javascript5/20/2023 ![]() ![]() ![]() In the end, the returned value will be 10. 1 + 2 is 3 so in the second iteration accumulator will be 3 and currentValue will be 3 (since it's the item in the array that is after 2), and so on. So, in the example above, in the first iteration accumulator will be 1 and currentValue will be 2. By default, its initial value is the value of the first element and the iteration starts from the second element. The accumulator parameter is the result after the last iteration before the current one, and its value, in the end, will be the value returned. reduce ( ( accumulator, currentValue ) => accumulator + currentValue )
0 Comments
Leave a Reply. |