Array_.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_.pullAllWithCollectionDateFunctionLang_.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_.isNumberMathObjectSeqString_.camelCase_.capitalize_.deburr_.endsWith_.escape_.escapeRegExp_.kebabCase_.lowerCase_.lowerFirst_.pad_.padEnd_.padStart(string ='',length = 0,chars ='')_.parseInt_.repeat(string ='',n = 1)_.replace(string ='',pattern,replacement)_.snakeCase_.split_.startCase_.startsWith_.template_.toLower_.toUpper_.trim_.trimEnd(string ='',chars = whitespace)_.trimStart_.truncate_.unescape_.upperCase_.upperFirstUtil_.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_.uniqueIdMethods迭代元素collection与iteratee为每个元素调用。迭代器调用三个参数:(value,index | key,collection)。迭代器函数可以通过显式提前退出迭代,返回false。
注意:与其他“集合”方法一样,具有“长度”属性的对象与数组一样迭代。为了避免这种行为,使用_.forIn或_.forOwn用于对象迭代。
0.1.0
_.each
collection (Array | Object):迭代的集合。 [iteratee=_.identity] (Function):每次迭代调用的函数。 (*): 返回 collection.
_.forEach([1, 2], function(value) {
console.log(value);
});
// => Logs `1` then `2`.
_.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
console.log(key);
});
// => Logs 'a' then 'b' (iteration order is not guaranteed).