- _-chunk
- _-compact
- _-concat
- _-difference
- _-differenceBy
- _-differenceWith
- _-drop
- _-dropRight
- _-dropRightWhile
- _-dropWhile
- _-fill
- _-findIndex
- _-findLastIndex
- _-flatten
- _-flattenDeep
- _-flattenDepth
- _-fromPairs
- _-head
- _-indexOf
- _-initial
- _-intersection
- _-intersectionBy
- _-intersectionWith
- _-join
- _-last
- _-lastIndexOf
- _-nth
- _-pull
- _-pullAll
- _-pullAllBy
- _-pullAllWith
- _-pullAt
- _-remove
- _-reverse
- _-slice
- _-sortedIndex
- _-sortedIndexBy
- _-sortedIndexOf
- _-sortedLastIndex
- _-sortedLastIndexBy
- _-sortedLastIndexOf
- _-sortedUniq
- _-sortedUniqBy
- _-tail
- _-take
- _-takeRight
- _-takeRightWhile
- _-takeWhile
- _-union
- _-unionBy
- _-unionWith
- _-uniq
- _-uniqBy
- _-uniqWith
- _-unzip
- _-unzipWith
- _-without
- _-xor
- _-xorBy
- _-xorWith
- _-zip
- _-zipObject
- _-zipObjectDeep
- _-zipWith
- _-countBy
- _-every
- _-filter
- _-find
- _-findLast
- _-flatMap
- _-flatMapDeep
- _-flatMapDepth
- _-forEach
- _-forEachRight
- _-groupBy
- _-includes
- _-invokeMap
- _-keyBy
- _-map
- _-orderBy
- _-partition
- _-reduce
- _-reduceRight
- _-reject
- _-sample
- _-sampleSize
- _-shuffle
- _-size
- _-some
- _-sortBy
- _-now
- _-after
- _-ary
- _-before
- _-bind
- _-bindKey
- _-curry
- _-curryRight
- _-debounce
- _-defer
- _-delay
- _-flip
- _-memoize
- _-negate
- _-once
- _-overArgs
- _-partial
- _-partialRight
- _-rearg
- _-rest
- _-spread
- _-throttle
- _-unary
- _-wrap
- _-castArray
- _-clone
- _-cloneDeep
- _-cloneDeepWith
- _-cloneWith
- _-conformsTo
- _-eq
- _-gt
- _-gte
- _-isArguments
- _-isArray
- _-isArrayBuffer
- _-isArrayLike
- _-isArrayLikeObject
- _-isBoolean
- _-isBuffer
- _-isDate
- _-isElement
- _-isEmpty
- _-isEqual
- _-isEqualWith
- _-isError
- _-isFinite
- _-isFunction
- _-isInteger
- _-isLength
- _-isMap
- _-isMatch
- _-isMatchWith
- _-isNaN
- _-isNative
- _-isNil
- _-isNull
- _-isNumber
- _-isObject
- _-isObjectLike
- _-isPlainObject
- _-isRegExp
- _-isSafeInteger
- _-isSet
- _-isString
- _-isSymbol
- _-isTypedArray
- _-isUndefined
- _-isWeakMap
- _-isWeakSet
- _-lt
- _-lte
- _-toArray
- _-toFinite
- _-toInteger
- _-toLength
- _-toNumber
- _-toPlainObject
- _-toSafeInteger
- _-toString
- _-add
- _-ceil
- _-divide
- _-floor
- _-max
- _-maxBy
- _-mean
- _-meanBy
- _-min
- _-minBy
- _-multiply
- _-round
- _-subtract
- _-sum
- _-sumBy
- _-clamp
- _-inRange
- _-random
- _-assign
- _-assignIn
- _-assignInWith
- _-assignWith
- _-at
- _-create
- _-defaults
- _-defaultsDeep
- _-findKey
- _-findLastKey
- _-forIn
- _-forInRight
- _-forOwn
- _-forOwnRight
- _-functions
- _-functionsIn
- _-get
- _-has
- _-hasIn
- _-invert
- _-invertBy
- _-invoke
- _-keys
- _-keysIn
- _-mapKeys
- _-mapValues
- _-merge
- _-mergeWith
- _-omit
- _-omitBy
- _-pick
- _-pickBy
- _-result
- _-set
- _-setWith
- _-toPairs
- _-toPairsIn
- _-transform
- _-unset
- _-update
- _-updateWith
- _-values
- _-valuesIn
- _
- _-chain
- _-tap
- _-thru
- _-prototypeSymbol-iterator
- _-prototype-at
- _-prototype-chain
- _-prototype-commit
- _-prototype-next
- _-prototype-plant
- _-prototype-reverse
- _-prototype-value
- _-camelCase
- _-capitalize
- _-deburr
- _-endsWith
- _-escape
- _-escapeRegExp
- _-kebabCase
- _-lowerCase
- _-lowerFirst
- _-pad
- _-padEnd
- _-padStart
- _-parseInt
- _-repeat
- _-replace
- _-snakeCase
- _-split
- _-startCase
- _-startsWith
- _-template
- _-toLower
- _-toUpper
- _-trim
- _-trimEnd
- _-trimStart
- _-truncate
- _-unescape
- _-upperCase
- _-upperFirst
- _-words
- _-attempt
- _-bindAll
- _-cond
- _-conforms
- _-constant
- _-defaultTo
- _-flow
- _-flowRight
- _-identity
- _-iteratee
- _-matches
- _-matchesProperty
- _-method
- _-methodOf
- _-mixin
- _-noConflict
- _-noop
- _-nthArg
- _-over
- _-overEvery
- _-overSome
- _-property
- _-propertyOf
- _-range
- _-rangeRight
- _-runInContext
- _-stubArray
- _-stubFalse
- _-stubObject
- _-stubString
- _-stubTrue
- _-times
- _-toPath
- _-uniqueId
- _-VERSION
- _-templateSettings
- _-templateSettings-escape
- _-templateSettings-evaluate
- _-templateSettings-imports
- _-templateSettings-interpolate
- _-templateSettings-variable
- _-templateSettings-imports-_
- 索引
文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
_-reduce
_.reduce(collection, [iteratee=_.identity], [accumulator])
View in source See the npm package
压缩 collection
(集合)为一个值,通过 iteratee
(迭代函数)遍历 collection
(集合)中的每个元素,每次返回的值会作为下一次迭代使用(愚人码头注:作为iteratee
(迭代函数)的第一个参数使用)。 如果没有提供 accumulator
,则 collection
(集合)中的第一个元素作为初始值。(愚人码头注:accumulator
参数在第一次迭代的时候作为iteratee
(迭代函数)第一个参数使用。) iteratee 调用4个参数:
(accumulator, value, index|key, collection).
lodash 中有许多方法是防止作为其他方法的迭代函数(愚人码头注:即不能作为iteratee参数传递给其他方法),例如: _.reduce
, _.reduceRight
, 和 _.transform
。
受保护的方法有(愚人码头注:即这些方法不能使用 _.reduce
, _.reduceRight
, 和 _.transform
作为 iteratee 迭代函数参数):
assign
, defaults
, defaultsDeep
, includes
, merge
, orderBy
, 和 sortBy
添加版本
0.1.0
参数
collection
(Array|Object): 用来迭代的集合。[iteratee=_.identity]
(Function): 每次迭代调用的函数。[accumulator]
(*): 初始值。
返回
(*): 返回累加后的值。
例子
_.reduce([1, 2], function(sum, n) { return sum + n;}, 0);// => 3 _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { (result[value] || (result[value] = [])).push(key); return result;}, {});// => { '1': ['a', 'c'], '2': ['b'] } (无法保证遍历的顺序)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论