Skip to content

Commit 121166a

Browse files
committed
[update] add index param for reduce() method of data collection
1 parent 5306d60 commit 121166a

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

docs/data_collection/api/datacollection_reduce_method.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@ description: You can explore the reduce method of DataCollection in the document
88

99
@short: reduces the array to a single value
1010

11-
@signature: {'reduce(callback: (acc: any, item: any) => any, acc: any): any;'}
11+
@signature: {'reduce(callback: (acc: any, item: any, index?: number) => any, acc: any): any;'}
1212

1313
@params:
1414

1515
- `callback: function` - a function that will be called for each item in the array. The function is called with the following parameters:
1616
- `acc` - the *initialValue*, or the previously returned value of the function
1717
- `item` - the current item of a data collection
18+
- `index` - the index of the item
1819
- `acc: any` - a value to be passed to the function as the initial value
1920

2021
@returns:
2122
A single output value.
2223

2324
@example:
24-
const total = component.data.reduce(function(acc, item) {
25+
const total = component.data.reduce(function(acc, item, index) {
2526
return acc + item.value;
2627
}, 0);
2728

0 commit comments

Comments
 (0)