README.md (lodash-3.0.0) | : | README.md (lodash-4.0.0) |
---|---|---|
# <a href="https://lodash.com/">lodash</a> <span>v3.0.0</span> | # <a href="https://lodash.com/">lodash</a> <span>v4.0.0</span> | |
<!-- div class="toc-container" --> | <!-- div class="toc-container" --> | |
<!-- div --> | <!-- div --> | |
## <a id="array"></a>`Array` | ## `Array` | |
* <a href="#_chunkarray-size1">`_.chunk`</a> | * <a href="#_chunkarray-size0">`_.chunk`</a> | |
* <a href="#_compactarray">`_.compact`</a> | * <a href="#_compactarray">`_.compact`</a> | |
* <a href="#_concatarray-values">`_.concat`</a> | ||
* <a href="#_differencearray-values">`_.difference`</a> | * <a href="#_differencearray-values">`_.difference`</a> | |
* <a href="#_differencebyarray-values-iteratee_identity">`_.differenceBy`</a> | ||
* <a href="#_differencewitharray-values-comparator">`_.differenceWith`</a> | ||
* <a href="#_droparray-n1">`_.drop`</a> | * <a href="#_droparray-n1">`_.drop`</a> | |
* <a href="#_droprightarray-n1">`_.dropRight`</a> | * <a href="#_droprightarray-n1">`_.dropRight`</a> | |
* <a href="#_droprightwhilearray-predicate_identity-thisarg">`_.dropRightWhile`< | * <a href="#_droprightwhilearray-predicate_identity">`_.dropRightWhile`</a> | |
/a> | * <a href="#_dropwhilearray-predicate_identity">`_.dropWhile`</a> | |
* <a href="#_dropwhilearray-predicate_identity-thisarg">`_.dropWhile`</a> | * <a href="#_fillarray-value-start0-endarraylength">`_.fill`</a> | |
* <a href="#_findindexarray-predicate_identity-thisarg">`_.findIndex`</a> | * <a href="#_findindexarray-predicate_identity">`_.findIndex`</a> | |
* <a href="#_findlastindexarray-predicate_identity-thisarg">`_.findLastIndex`</a | * <a href="#_findlastindexarray-predicate_identity">`_.findLastIndex`</a> | |
> | * <a href="#_headarray" class="alias">`_.first` -> `head`</a> | |
* <a href="#_firstarray">`_.first`</a> | * <a href="#_flatmaparray-iteratee_identity">`_.flatMap`</a> | |
* <a href="#_flattenarray-isdeep">`_.flatten`</a> | * <a href="#_flattenarray">`_.flatten`</a> | |
* <a href="#_flattendeeparray">`_.flattenDeep`</a> | * <a href="#_flattendeeparray">`_.flattenDeep`</a> | |
* <a href="#_firstarray" class="alias">`_.head` -> `first`</a> | * <a href="#_frompairspairs">`_.fromPairs`</a> | |
* <a href="#_headarray">`_.head`</a> | ||
* <a href="#_indexofarray-value-fromindex0">`_.indexOf`</a> | * <a href="#_indexofarray-value-fromindex0">`_.indexOf`</a> | |
* <a href="#_initialarray">`_.initial`</a> | * <a href="#_initialarray">`_.initial`</a> | |
* <a href="#_intersectionarrays">`_.intersection`</a> | * <a href="#_intersectionarrays">`_.intersection`</a> | |
* <a href="#_intersectionbyarrays-iteratee_identity">`_.intersectionBy`</a> | ||
* <a href="#_intersectionwitharrays-comparator">`_.intersectionWith`</a> | ||
* <a href="#_joinarray-separator-">`_.join`</a> | ||
* <a href="#_lastarray">`_.last`</a> | * <a href="#_lastarray">`_.last`</a> | |
* <a href="#_lastindexofarray-value">`_.lastIndexOf`</a> | * <a href="#_lastindexofarray-value-fromindexarraylength-1">`_.lastIndexOf`</a> | |
* <a href="#_zipobjectprops-values" class="alias">`_.object` -> `zipObject`</a> | ||
* <a href="#_pullarray-values">`_.pull`</a> | * <a href="#_pullarray-values">`_.pull`</a> | |
* <a href="#_pullallarray-values">`_.pullAll`</a> | ||
* <a href="#_pullallbyarray-values-iteratee_identity">`_.pullAllBy`</a> | ||
* <a href="#_pullatarray-indexes">`_.pullAt`</a> | * <a href="#_pullatarray-indexes">`_.pullAt`</a> | |
* <a href="#_removearray-predicate_identity-thisarg">`_.remove`</a> | * <a href="#_removearray-predicate_identity">`_.remove`</a> | |
* <a href="#_restarray">`_.rest`</a> | * <a href="#_slicearray-start0-endarraylength">`_.slice`</a> | |
* <a href="#_slicearray-start0">`_.slice`</a> | * <a href="#_sortedindexarray-value">`_.sortedIndex`</a> | |
* <a href="#_sortedindexarray-value-iteratee_identity-thisarg">`_.sortedIndex`</ | * <a href="#_sortedindexbyarray-value-iteratee_identity">`_.sortedIndexBy`</a> | |
a> | * <a href="#_sortedindexofarray-value">`_.sortedIndexOf`</a> | |
* <a href="#_sortedlastindexarray-value-iteratee_identity-thisarg">`_.sortedLast | * <a href="#_sortedlastindexarray-value">`_.sortedLastIndex`</a> | |
Index`</a> | * <a href="#_sortedlastindexbyarray-value-iteratee_identity">`_.sortedLastIndexB | |
* <a href="#_restarray" class="alias">`_.tail` -> `rest`</a> | y`</a> | |
* <a href="#_sortedlastindexofarray-value">`_.sortedLastIndexOf`</a> | ||
* <a href="#_sorteduniqarray">`_.sortedUniq`</a> | ||
* <a href="#_sorteduniqbyarray-iteratee">`_.sortedUniqBy`</a> | ||
* <a href="#_tailarray">`_.tail`</a> | ||
* <a href="#_takearray-n1">`_.take`</a> | * <a href="#_takearray-n1">`_.take`</a> | |
* <a href="#_takerightarray-n1">`_.takeRight`</a> | * <a href="#_takerightarray-n1">`_.takeRight`</a> | |
* <a href="#_takerightwhilearray-predicate_identity-thisarg">`_.takeRightWhile`< | * <a href="#_takerightwhilearray-predicate_identity">`_.takeRightWhile`</a> | |
/a> | * <a href="#_takewhilearray-predicate_identity">`_.takeWhile`</a> | |
* <a href="#_takewhilearray-predicate_identity-thisarg">`_.takeWhile`</a> | ||
* <a href="#_unionarrays">`_.union`</a> | * <a href="#_unionarrays">`_.union`</a> | |
* <a href="#_uniqarray-issorted-iteratee-thisarg">`_.uniq`</a> | * <a href="#_unionbyarrays-iteratee_identity">`_.unionBy`</a> | |
* <a href="#_uniqarray-issorted-iteratee-thisarg" class="alias">`_.unique` -> `u | * <a href="#_unionwitharrays-comparator">`_.unionWith`</a> | |
niq`</a> | * <a href="#_uniqarray">`_.uniq`</a> | |
* <a href="#_uniqbyarray-iteratee_identity">`_.uniqBy`</a> | ||
* <a href="#_uniqwitharray-comparator">`_.uniqWith`</a> | ||
* <a href="#_unziparray">`_.unzip`</a> | * <a href="#_unziparray">`_.unzip`</a> | |
* <a href="#_unzipwitharray-iteratee_identity">`_.unzipWith`</a> | ||
* <a href="#_withoutarray-values">`_.without`</a> | * <a href="#_withoutarray-values">`_.without`</a> | |
* <a href="#_xorarrays">`_.xor`</a> | * <a href="#_xorarrays">`_.xor`</a> | |
* <a href="#_xorbyarrays-iteratee_identity">`_.xorBy`</a> | ||
* <a href="#_xorwitharrays-comparator">`_.xorWith`</a> | ||
* <a href="#_ziparrays">`_.zip`</a> | * <a href="#_ziparrays">`_.zip`</a> | |
* <a href="#_zipobjectprops-values">`_.zipObject`</a> | * <a href="#_zipobjectprops-values">`_.zipObject`</a> | |
* <a href="#_zipwitharrays-iteratee_identity">`_.zipWith`</a> | ||
<!-- /div --> | ||
<!-- div --> | ||
## <a id="chain"></a>`Chain` | ||
* <a href="#_value">`_`</a> | ||
* <a href="#_chainvalue">`_.chain`</a> | ||
* <a href="#_tapvalue-interceptor-thisarg">`_.tap`</a> | ||
* <a href="#_thruvalue-interceptor-thisarg">`_.thru`</a> | ||
* <a href="#_prototypechain">`_.prototype.chain`</a> | ||
* <a href="#_prototypereverse">`_.prototype.reverse`</a> | * <a href="#_prototypereverse">`_.prototype.reverse`</a> | |
* <a href="#_prototypevalue" class="alias">`_.prototype.toJSON` -> `value`</a> | ||
* <a href="#_prototypetostring">`_.prototype.toString`</a> | ||
* <a href="#_prototypevalue">`_.prototype.value`</a> | ||
* <a href="#_prototypevalue" class="alias">`_.prototype.valueOf` -> `value`</a> | ||
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
## <a id="collection"></a>`Collection` | ## `Collection` | |
* <a href="#_everycollection-predicate_identity-thisarg" class="alias">`_.all` - | * <a href="#_countbycollection-iteratee_identity">`_.countBy`</a> | |
> `every`</a> | * <a href="#_foreachcollection-iteratee_identity" class="alias">`_.each` -> `for | |
* <a href="#_somecollection-predicate_identity-thisarg" class="alias">`_.any` -> | Each`</a> | |
`some`</a> | * <a href="#_foreachrightcollection-iteratee_identity" class="alias">`_.eachRigh | |
* <a href="#_atcollection-props">`_.at`</a> | t` -> `forEachRight`</a> | |
* <a href="#_mapcollection-iteratee_identity-thisarg" class="alias">`_.collect` | * <a href="#_everycollection-predicate_identity">`_.every`</a> | |
-> `map`</a> | * <a href="#_filtercollection-predicate_identity">`_.filter`</a> | |
* <a href="#_includescollection-target-fromindex0" class="alias">`_.contains` -> | * <a href="#_findcollection-predicate_identity">`_.find`</a> | |
`includes`</a> | * <a href="#_findlastcollection-predicate_identity">`_.findLast`</a> | |
* <a href="#_countbycollection-iteratee_identity-thisarg">`_.countBy`</a> | * <a href="#_foreachcollection-iteratee_identity">`_.forEach`</a> | |
* <a href="#_findcollection-predicate_identity-thisarg" class="alias">`_.detect` | * <a href="#_foreachrightcollection-iteratee_identity">`_.forEachRight`</a> | |
-> `find`</a> | * <a href="#_groupbycollection-iteratee_identity">`_.groupBy`</a> | |
* <a href="#_foreachcollection-iteratee_identity-thisarg" class="alias">`_.each` | * <a href="#_includescollection-value-fromindex0">`_.includes`</a> | |
-> `forEach`</a> | * <a href="#_invokemapcollection-path-args">`_.invokeMap`</a> | |
* <a href="#_foreachrightcollection-iteratee_identity-thisarg" class="alias">`_. | * <a href="#_keybycollection-iteratee_identity">`_.keyBy`</a> | |
eachRight` -> `forEachRight`</a> | * <a href="#_mapcollection-iteratee_identity">`_.map`</a> | |
* <a href="#_everycollection-predicate_identity-thisarg">`_.every`</a> | * <a href="#_orderbycollection-iteratees-_identity-orders">`_.orderBy`</a> | |
* <a href="#_filtercollection-predicate_identity-thisarg">`_.filter`</a> | * <a href="#_partitioncollection-predicate_identity">`_.partition`</a> | |
* <a href="#_findcollection-predicate_identity-thisarg">`_.find`</a> | * <a href="#_reducecollection-iteratee_identity-accumulator">`_.reduce`</a> | |
* <a href="#_findlastcollection-predicate_identity-thisarg">`_.findLast`</a> | * <a href="#_reducerightcollection-iteratee_identity-accumulator">`_.reduceRight | |
* <a href="#_findwherecollection-source">`_.findWhere`</a> | `</a> | |
* <a href="#_reducecollection-iteratee_identity-accumulator-thisarg" class="alia | * <a href="#_rejectcollection-predicate_identity">`_.reject`</a> | |
s">`_.foldl` -> `reduce`</a> | * <a href="#_samplecollection">`_.sample`</a> | |
* <a href="#_reducerightcollection-iteratee_identity-accumulator-thisarg" class= | * <a href="#_samplesizecollection-n0">`_.sampleSize`</a> | |
"alias">`_.foldr` -> `reduceRight`</a> | ||
* <a href="#_foreachcollection-iteratee_identity-thisarg">`_.forEach`</a> | ||
* <a href="#_foreachrightcollection-iteratee_identity-thisarg">`_.forEachRight`< | ||
/a> | ||
* <a href="#_groupbycollection-iteratee_identity-thisarg">`_.groupBy`</a> | ||
* <a href="#_includescollection-target-fromindex0" class="alias">`_.include` -> | ||
`includes`</a> | ||
* <a href="#_includescollection-target-fromindex0">`_.includes`</a> | ||
* <a href="#_indexbycollection-iteratee_identity-thisarg">`_.indexBy`</a> | ||
* <a href="#_reducecollection-iteratee_identity-accumulator-thisarg" class="alia | ||
s">`_.inject` -> `reduce`</a> | ||
* <a href="#_invokecollection-methodname-args">`_.invoke`</a> | ||
* <a href="#_mapcollection-iteratee_identity-thisarg">`_.map`</a> | ||
* <a href="#_maxcollection-iteratee-thisarg">`_.max`</a> | ||
* <a href="#_mincollection-iteratee-thisarg">`_.min`</a> | ||
* <a href="#_partitioncollection-predicate_identity-thisarg">`_.partition`</a> | ||
* <a href="#_pluckcollection-key">`_.pluck`</a> | ||
* <a href="#_reducecollection-iteratee_identity-accumulator-thisarg">`_.reduce`< | ||
/a> | ||
* <a href="#_reducerightcollection-iteratee_identity-accumulator-thisarg">`_.red | ||
uceRight`</a> | ||
* <a href="#_rejectcollection-predicate_identity-thisarg">`_.reject`</a> | ||
* <a href="#_samplecollection-n">`_.sample`</a> | ||
* <a href="#_filtercollection-predicate_identity-thisarg" class="alias">`_.selec | ||
t` -> `filter`</a> | ||
* <a href="#_shufflecollection">`_.shuffle`</a> | * <a href="#_shufflecollection">`_.shuffle`</a> | |
* <a href="#_sizecollection">`_.size`</a> | * <a href="#_sizecollection">`_.size`</a> | |
* <a href="#_somecollection-predicate_identity-thisarg">`_.some`</a> | * <a href="#_somecollection-predicate_identity">`_.some`</a> | |
* <a href="#_sortbycollection-iteratee_identity-thisarg">`_.sortBy`</a> | * <a href="#_sortbycollection-iteratees-_identity">`_.sortBy`</a> | |
* <a href="#_sortbyallcollection-props">`_.sortByAll`</a> | ||
* <a href="#_wherecollection-source">`_.where`</a> | ||
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
## <a id="date"></a>`Date` | ## `Date` | |
* <a href="#_now">`_.now`</a> | * <a href="#_now">`_.now`</a> | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
## <a id="function"></a>`Function` | ## `Function` | |
* <a href="#_aftern-func">`_.after`</a> | * <a href="#_aftern-func">`_.after`</a> | |
* <a href="#_aryfunc">`_.ary`</a> | * <a href="#_aryfunc-nfunclength">`_.ary`</a> | |
* <a href="#_flowrightfuncs" class="alias">`_.backflow` -> `flowRight`</a> | ||
* <a href="#_beforen-func">`_.before`</a> | * <a href="#_beforen-func">`_.before`</a> | |
* <a href="#_bindfunc-thisarg-args">`_.bind`</a> | * <a href="#_bindfunc-thisarg-partials">`_.bind`</a> | |
* <a href="#_bindallobject-methodnames">`_.bindAll`</a> | * <a href="#_bindkeyobject-key-partials">`_.bindKey`</a> | |
* <a href="#_bindkeyobject-key-args">`_.bindKey`</a> | * <a href="#_curryfunc-arityfunclength">`_.curry`</a> | |
* <a href="#_flowrightfuncs" class="alias">`_.compose` -> `flowRight`</a> | * <a href="#_curryrightfunc-arityfunclength">`_.curryRight`</a> | |
* <a href="#_curryfunc">`_.curry`</a> | * <a href="#_debouncefunc-wait0-options">`_.debounce`</a> | |
* <a href="#_curryrightfunc">`_.curryRight`</a> | ||
* <a href="#_debouncefunc-wait-options-optionsleadingfalse-optionsmaxwait-option | ||
strailingtrue">`_.debounce`</a> | ||
* <a href="#_deferfunc-args">`_.defer`</a> | * <a href="#_deferfunc-args">`_.defer`</a> | |
* <a href="#_delayfunc-wait-args">`_.delay`</a> | * <a href="#_delayfunc-wait-args">`_.delay`</a> | |
* <a href="#_flowfuncs">`_.flow`</a> | * <a href="#_flipfunc">`_.flip`</a> | |
* <a href="#_flowrightfuncs">`_.flowRight`</a> | ||
* <a href="#_memoizefunc-resolver">`_.memoize`</a> | * <a href="#_memoizefunc-resolver">`_.memoize`</a> | |
* <a href="#_negatepredicate">`_.negate`</a> | * <a href="#_negatepredicate">`_.negate`</a> | |
* <a href="#_oncefunc">`_.once`</a> | * <a href="#_oncefunc">`_.once`</a> | |
* <a href="#_partialfunc-args">`_.partial`</a> | * <a href="#_overargsfunc-transforms">`_.overArgs`</a> | |
* <a href="#_partialrightfunc-args">`_.partialRight`</a> | * <a href="#_partialfunc-partials">`_.partial`</a> | |
* <a href="#_partialrightfunc-partials">`_.partialRight`</a> | ||
* <a href="#_reargfunc-indexes">`_.rearg`</a> | * <a href="#_reargfunc-indexes">`_.rearg`</a> | |
* <a href="#_throttlefunc-wait-options-optionsleadingtrue-optionstrailingtrue">` | * <a href="#_restfunc-startfunclength-1">`_.rest`</a> | |
_.throttle`</a> | * <a href="#_spreadfunc">`_.spread`</a> | |
* <a href="#_throttlefunc-wait0-options">`_.throttle`</a> | ||
* <a href="#_unaryfunc">`_.unary`</a> | ||
* <a href="#_wrapvalue-wrapper">`_.wrap`</a> | * <a href="#_wrapvalue-wrapper">`_.wrap`</a> | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
## <a id="lang"></a>`Lang` | ## `Lang` | |
* <a href="#_clonevalue-isdeep-customizer-thisarg">`_.clone`</a> | * <a href="#_clonevalue">`_.clone`</a> | |
* <a href="#_clonedeepvalue-customizer-thisarg">`_.cloneDeep`</a> | * <a href="#_clonedeepvalue">`_.cloneDeep`</a> | |
* <a href="#_clonedeepwithvalue-customizer">`_.cloneDeepWith`</a> | ||
* <a href="#_clonewithvalue-customizer">`_.cloneWith`</a> | ||
* <a href="#_eqvalue-other">`_.eq`</a> | ||
* <a href="#_gtvalue-other">`_.gt`</a> | ||
* <a href="#_gtevalue-other">`_.gte`</a> | ||
* <a href="#_isargumentsvalue">`_.isArguments`</a> | * <a href="#_isargumentsvalue">`_.isArguments`</a> | |
* <a href="#_isarrayvalue">`_.isArray`</a> | * <a href="#_isarrayvalue">`_.isArray`</a> | |
* <a href="#_isarraylikevalue">`_.isArrayLike`</a> | ||
* <a href="#_isarraylikeobjectvalue">`_.isArrayLikeObject`</a> | ||
* <a href="#_isbooleanvalue">`_.isBoolean`</a> | * <a href="#_isbooleanvalue">`_.isBoolean`</a> | |
* <a href="#_isdatevalue">`_.isDate`</a> | * <a href="#_isdatevalue">`_.isDate`</a> | |
* <a href="#_iselementvalue">`_.isElement`</a> | * <a href="#_iselementvalue">`_.isElement`</a> | |
* <a href="#_isemptyvalue">`_.isEmpty`</a> | * <a href="#_isemptyvalue">`_.isEmpty`</a> | |
* <a href="#_isequalvalue-other-customizer-thisarg">`_.isEqual`</a> | * <a href="#_isequalvalue-other">`_.isEqual`</a> | |
* <a href="#_isequalwithvalue-other-customizer">`_.isEqualWith`</a> | ||
* <a href="#_iserrorvalue">`_.isError`</a> | * <a href="#_iserrorvalue">`_.isError`</a> | |
* <a href="#_isfinitevalue">`_.isFinite`</a> | * <a href="#_isfinitevalue">`_.isFinite`</a> | |
* <a href="#_isfunctionvalue">`_.isFunction`</a> | * <a href="#_isfunctionvalue">`_.isFunction`</a> | |
* <a href="#_ismatchsource-source-customizer-thisarg">`_.isMatch`</a> | * <a href="#_isintegervalue">`_.isInteger`</a> | |
* <a href="#_islengthvalue">`_.isLength`</a> | ||
* <a href="#_ismatchobject-source">`_.isMatch`</a> | ||
* <a href="#_ismatchwithobject-source-customizer">`_.isMatchWith`</a> | ||
* <a href="#_isnanvalue">`_.isNaN`</a> | * <a href="#_isnanvalue">`_.isNaN`</a> | |
* <a href="#_isnativevalue">`_.isNative`</a> | * <a href="#_isnativevalue">`_.isNative`</a> | |
* <a href="#_isnilvalue">`_.isNil`</a> | ||
* <a href="#_isnullvalue">`_.isNull`</a> | * <a href="#_isnullvalue">`_.isNull`</a> | |
* <a href="#_isnumbervalue">`_.isNumber`</a> | * <a href="#_isnumbervalue">`_.isNumber`</a> | |
* <a href="#_isobjectvalue">`_.isObject`</a> | * <a href="#_isobjectvalue">`_.isObject`</a> | |
* <a href="#_isobjectlikevalue">`_.isObjectLike`</a> | ||
* <a href="#_isplainobjectvalue">`_.isPlainObject`</a> | * <a href="#_isplainobjectvalue">`_.isPlainObject`</a> | |
* <a href="#_isregexpvalue">`_.isRegExp`</a> | * <a href="#_isregexpvalue">`_.isRegExp`</a> | |
* <a href="#_issafeintegervalue">`_.isSafeInteger`</a> | ||
* <a href="#_isstringvalue">`_.isString`</a> | * <a href="#_isstringvalue">`_.isString`</a> | |
* <a href="#_issymbolvalue">`_.isSymbol`</a> | ||
* <a href="#_istypedarrayvalue">`_.isTypedArray`</a> | * <a href="#_istypedarrayvalue">`_.isTypedArray`</a> | |
* <a href="#_isundefinedvalue">`_.isUndefined`</a> | * <a href="#_isundefinedvalue">`_.isUndefined`</a> | |
* <a href="#_ltvalue-other">`_.lt`</a> | ||
* <a href="#_ltevalue-other">`_.lte`</a> | ||
* <a href="#_toarrayvalue">`_.toArray`</a> | * <a href="#_toarrayvalue">`_.toArray`</a> | |
* <a href="#_tointegervalue">`_.toInteger`</a> | ||
* <a href="#_tolengthvalue">`_.toLength`</a> | ||
* <a href="#_tonumbervalue">`_.toNumber`</a> | ||
* <a href="#_toplainobjectvalue">`_.toPlainObject`</a> | * <a href="#_toplainobjectvalue">`_.toPlainObject`</a> | |
* <a href="#_tosafeintegervalue">`_.toSafeInteger`</a> | ||
* <a href="#_tostringvalue">`_.toString`</a> | ||
<!-- /div --> | ||
<!-- div --> | ||
## `Math` | ||
* <a href="#_addaugend-addend">`_.add`</a> | ||
* <a href="#_ceilnumber-precision0">`_.ceil`</a> | ||
* <a href="#_floornumber-precision0">`_.floor`</a> | ||
* <a href="#_maxarray">`_.max`</a> | ||
* <a href="#_maxbyarray-iteratee_identity">`_.maxBy`</a> | ||
* <a href="#_meanarray">`_.mean`</a> | ||
* <a href="#_minarray">`_.min`</a> | ||
* <a href="#_minbyarray-iteratee_identity">`_.minBy`</a> | ||
* <a href="#_roundnumber-precision0">`_.round`</a> | ||
* <a href="#_subtractminuend-subtrahend">`_.subtract`</a> | ||
* <a href="#_sumarray">`_.sum`</a> | ||
* <a href="#_sumbyarray-iteratee_identity">`_.sumBy`</a> | ||
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
## <a id="number"></a>`Number` | ## `Number` | |
* <a href="#_randommin0-max1-floating">`_.random`</a> | * <a href="#_clampnumber-lower-upper">`_.clamp`</a> | |
* <a href="#_inrangenumber-start0-end">`_.inRange`</a> | ||
* <a href="#_randomlower0-upper1-floating">`_.random`</a> | ||
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
## <a id="object"></a>`Object` | ## `Object` | |
* <a href="#_assignobject-sources-customizer-thisarg">`_.assign`</a> | * <a href="#_assignobject-sources">`_.assign`</a> | |
* <a href="#_assigninobject-sources">`_.assignIn`</a> | ||
* <a href="#_assigninwithobject-sources-customizer">`_.assignInWith`</a> | ||
* <a href="#_assignwithobject-sources-customizer">`_.assignWith`</a> | ||
* <a href="#_atobject-paths">`_.at`</a> | ||
* <a href="#_createprototype-properties">`_.create`</a> | * <a href="#_createprototype-properties">`_.create`</a> | |
* <a href="#_defaultsobject-sources">`_.defaults`</a> | * <a href="#_defaultsobject-sources">`_.defaults`</a> | |
* <a href="#_assignobject-sources-customizer-thisarg" class="alias">`_.extend` - | * <a href="#_defaultsdeepobject-sources">`_.defaultsDeep`</a> | |
> `assign`</a> | * <a href="#_assigninobject-sources" class="alias">`_.extend` -> `assignIn`</a> | |
* <a href="#_findkeyobject-predicate_identity-thisarg">`_.findKey`</a> | * <a href="#_assigninwithobject-sources-customizer" class="alias">`_.extendWith` | |
* <a href="#_findlastkeyobject-predicate_identity-thisarg">`_.findLastKey`</a> | -> `assignInWith`</a> | |
* <a href="#_forinobject-iteratee_identity-thisarg">`_.forIn`</a> | * <a href="#_findkeyobject-predicate_identity">`_.findKey`</a> | |
* <a href="#_forinrightobject-iteratee_identity-thisarg">`_.forInRight`</a> | * <a href="#_findlastkeyobject-predicate_identity">`_.findLastKey`</a> | |
* <a href="#_forownobject-iteratee_identity-thisarg">`_.forOwn`</a> | * <a href="#_forinobject-iteratee_identity">`_.forIn`</a> | |
* <a href="#_forownrightobject-iteratee_identity-thisarg">`_.forOwnRight`</a> | * <a href="#_forinrightobject-iteratee_identity">`_.forInRight`</a> | |
* <a href="#_forownobject-iteratee_identity">`_.forOwn`</a> | ||
* <a href="#_forownrightobject-iteratee_identity">`_.forOwnRight`</a> | ||
* <a href="#_functionsobject">`_.functions`</a> | * <a href="#_functionsobject">`_.functions`</a> | |
* <a href="#_hasobject-key">`_.has`</a> | * <a href="#_functionsinobject">`_.functionsIn`</a> | |
* <a href="#_invertobject-multivalue">`_.invert`</a> | * <a href="#_getobject-path-defaultvalue">`_.get`</a> | |
* <a href="#_hasobject-path">`_.has`</a> | ||
* <a href="#_hasinobject-path">`_.hasIn`</a> | ||
* <a href="#_invertobject-multival">`_.invert`</a> | ||
* <a href="#_invokeobject-path-args">`_.invoke`</a> | ||
* <a href="#_keysobject">`_.keys`</a> | * <a href="#_keysobject">`_.keys`</a> | |
* <a href="#_keysinobject">`_.keysIn`</a> | * <a href="#_keysinobject">`_.keysIn`</a> | |
* <a href="#_mapvaluesobject-iteratee_identity-thisarg">`_.mapValues`</a> | * <a href="#_mapkeysobject-iteratee_identity">`_.mapKeys`</a> | |
* <a href="#_mergeobject-sources-customizer-thisarg">`_.merge`</a> | * <a href="#_mapvaluesobject-iteratee_identity">`_.mapValues`</a> | |
* <a href="#_functionsobject" class="alias">`_.methods` -> `functions`</a> | * <a href="#_mergeobject-sources">`_.merge`</a> | |
* <a href="#_omitobject-predicate-thisarg">`_.omit`</a> | * <a href="#_mergewithobject-sources-customizer">`_.mergeWith`</a> | |
* <a href="#_pairsobject">`_.pairs`</a> | * <a href="#_omitobject-props">`_.omit`</a> | |
* <a href="#_pickobject-predicate-thisarg">`_.pick`</a> | * <a href="#_omitbyobject-predicate_identity">`_.omitBy`</a> | |
* <a href="#_resultobject-key-defaultvalue">`_.result`</a> | * <a href="#_pickobject-props">`_.pick`</a> | |
* <a href="#_transformobject-iteratee_identity-accumulator-thisarg">`_.transform | * <a href="#_pickbyobject-predicate_identity">`_.pickBy`</a> | |
`</a> | * <a href="#_resultobject-path-defaultvalue">`_.result`</a> | |
* <a href="#_setobject-path-value">`_.set`</a> | ||
* <a href="#_setwithobject-path-value-customizer">`_.setWith`</a> | ||
* <a href="#_topairsobject">`_.toPairs`</a> | ||
* <a href="#_topairsinobject">`_.toPairsIn`</a> | ||
* <a href="#_transformobject-iteratee_identity-accumulator">`_.transform`</a> | ||
* <a href="#_unsetobject-path">`_.unset`</a> | ||
* <a href="#_valuesobject">`_.values`</a> | * <a href="#_valuesobject">`_.values`</a> | |
* <a href="#_valuesinobject">`_.valuesIn`</a> | * <a href="#_valuesinobject">`_.valuesIn`</a> | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
## <a id="string"></a>`String` | ## `Seq` | |
* <a href="#_value">`_`</a> | ||
* <a href="#_chainvalue">`_.chain`</a> | ||
* <a href="#_tapvalue-interceptor">`_.tap`</a> | ||
* <a href="#_thruvalue-interceptor">`_.thru`</a> | ||
* <a href="#_wrapperflatmapiteratee_identity">`_.wrapperFlatMap`</a> | ||
* <a href="#_prototypesymboliterator">`_.prototype[Symbol.iterator]`</a> | ||
* <a href="#_prototypeatpaths">`_.prototype.at`</a> | ||
* <a href="#_prototypechain">`_.prototype.chain`</a> | ||
* <a href="#_prototypecommit">`_.prototype.commit`</a> | ||
* <a href="#_prototypenext">`_.prototype.next`</a> | ||
* <a href="#_prototypeplantvalue">`_.prototype.plant`</a> | ||
* <a href="#_prototypereverse">`_.prototype.reverse`</a> | ||
* <a href="#_prototypevalue" class="alias">`_.prototype.run` -> `value`</a> | ||
* <a href="#_prototypevalue" class="alias">`_.prototype.toJSON` -> `value`</a> | ||
* <a href="#_prototypevalue">`_.prototype.value`</a> | ||
* <a href="#_prototypevalue" class="alias">`_.prototype.valueOf` -> `value`</a> | ||
<!-- /div --> | ||
<!-- div --> | ||
## `String` | ||
* <a href="#_camelcasestring">`_.camelCase`</a> | * <a href="#_camelcasestring">`_.camelCase`</a> | |
* <a href="#_capitalizestring">`_.capitalize`</a> | * <a href="#_capitalizestring">`_.capitalize`</a> | |
* <a href="#_deburrstring">`_.deburr`</a> | * <a href="#_deburrstring">`_.deburr`</a> | |
* <a href="#_endswithstring-target-positionstringlength">`_.endsWith`</a> | * <a href="#_endswithstring-target-positionstringlength">`_.endsWith`</a> | |
* <a href="#_escapestring">`_.escape`</a> | * <a href="#_escapestring">`_.escape`</a> | |
* <a href="#_escaperegexpstring">`_.escapeRegExp`</a> | * <a href="#_escaperegexpstring">`_.escapeRegExp`</a> | |
* <a href="#_kebabcasestring">`_.kebabCase`</a> | * <a href="#_kebabcasestring">`_.kebabCase`</a> | |
* <a href="#_lowercasestring">`_.lowerCase`</a> | ||
* <a href="#_lowerfirststring">`_.lowerFirst`</a> | ||
* <a href="#_padstring-length0-chars">`_.pad`</a> | * <a href="#_padstring-length0-chars">`_.pad`</a> | |
* <a href="#_padleftstring-length0-chars">`_.padLeft`</a> | * <a href="#_padendstring-length0-chars">`_.padEnd`</a> | |
* <a href="#_padrightstring-length0-chars">`_.padRight`</a> | * <a href="#_padstartstring-length0-chars">`_.padStart`</a> | |
* <a href="#_parseintstring-radix">`_.parseInt`</a> | * <a href="#_parseintstring-radix">`_.parseInt`</a> | |
* <a href="#_repeatstring-n0">`_.repeat`</a> | * <a href="#_repeatstring-n0">`_.repeat`</a> | |
* <a href="#_replacestring-pattern-replacement">`_.replace`</a> | ||
* <a href="#_snakecasestring">`_.snakeCase`</a> | * <a href="#_snakecasestring">`_.snakeCase`</a> | |
* <a href="#_splitstring-separator-limit">`_.split`</a> | ||
* <a href="#_startcasestring">`_.startCase`</a> | ||
* <a href="#_startswithstring-target-position0">`_.startsWith`</a> | * <a href="#_startswithstring-target-position0">`_.startsWith`</a> | |
* <a href="#_templatestring-options-optionsescape-optionsevaluate-optionsimports | * <a href="#_templatestring-options">`_.template`</a> | |
-optionsinterpolate-optionssourceurl-optionsvariable">`_.template`</a> | * <a href="#_tolowerstring">`_.toLower`</a> | |
* <a href="#_toupperstring">`_.toUpper`</a> | ||
* <a href="#_trimstring-charswhitespace">`_.trim`</a> | * <a href="#_trimstring-charswhitespace">`_.trim`</a> | |
* <a href="#_trimleftstring-charswhitespace">`_.trimLeft`</a> | * <a href="#_trimendstring-charswhitespace">`_.trimEnd`</a> | |
* <a href="#_trimrightstring-charswhitespace">`_.trimRight`</a> | * <a href="#_trimstartstring-charswhitespace">`_.trimStart`</a> | |
* <a href="#_truncstring-options-optionslength30-optionsomission-optionsseparato | * <a href="#_truncatestring-options">`_.truncate`</a> | |
r">`_.trunc`</a> | ||
* <a href="#_unescapestring">`_.unescape`</a> | * <a href="#_unescapestring">`_.unescape`</a> | |
* <a href="#_uppercasestring">`_.upperCase`</a> | ||
* <a href="#_upperfirststring">`_.upperFirst`</a> | ||
* <a href="#_wordsstring-pattern">`_.words`</a> | * <a href="#_wordsstring-pattern">`_.words`</a> | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
## <a id="utility"></a>`Utility` | ## `Util` | |
* <a href="#_attemptfunc">`_.attempt`</a> | * <a href="#_attemptfunc">`_.attempt`</a> | |
* <a href="#_callbackfunc_identity-thisarg">`_.callback`</a> | * <a href="#_bindallobject-methodnames">`_.bindAll`</a> | |
* <a href="#_condpairs">`_.cond`</a> | ||
* <a href="#_conformssource">`_.conforms`</a> | ||
* <a href="#_constantvalue">`_.constant`</a> | * <a href="#_constantvalue">`_.constant`</a> | |
* <a href="#_flowfuncs">`_.flow`</a> | ||
* <a href="#_flowrightfuncs">`_.flowRight`</a> | ||
* <a href="#_identityvalue">`_.identity`</a> | * <a href="#_identityvalue">`_.identity`</a> | |
* <a href="#_callbackfunc_identity-thisarg" class="alias">`_.iteratee` -> `callb ack`</a> | * <a href="#_iterateefunc_identity">`_.iteratee`</a> | |
* <a href="#_matchessource">`_.matches`</a> | * <a href="#_matchessource">`_.matches`</a> | |
* <a href="#_mixinobjectthis-source-options-optionschaintrue">`_.mixin`</a> | * <a href="#_matchespropertypath-srcvalue">`_.matchesProperty`</a> | |
* <a href="#_methodpath-args">`_.method`</a> | ||
* <a href="#_methodofobject-args">`_.methodOf`</a> | ||
* <a href="#_mixinobjectlodash-source-options">`_.mixin`</a> | ||
* <a href="#_noconflict">`_.noConflict`</a> | * <a href="#_noconflict">`_.noConflict`</a> | |
* <a href="#_noop">`_.noop`</a> | * <a href="#_noop">`_.noop`</a> | |
* <a href="#_propertykey">`_.property`</a> | * <a href="#_nthargn0">`_.nthArg`</a> | |
* <a href="#_overiteratees">`_.over`</a> | ||
* <a href="#_overeverypredicates">`_.overEvery`</a> | ||
* <a href="#_oversomepredicates">`_.overSome`</a> | ||
* <a href="#_propertypath">`_.property`</a> | ||
* <a href="#_propertyofobject">`_.propertyOf`</a> | * <a href="#_propertyofobject">`_.propertyOf`</a> | |
* <a href="#_rangestart0-end-step1">`_.range`</a> | * <a href="#_rangestart0-end-step1">`_.range`</a> | |
* <a href="#_rangerightstart0-end-step1">`_.rangeRight`</a> | ||
* <a href="#_runincontextcontextroot">`_.runInContext`</a> | * <a href="#_runincontextcontextroot">`_.runInContext`</a> | |
* <a href="#_timesn-iteratee_identity-thisarg">`_.times`</a> | * <a href="#_timesn-iteratee_identity">`_.times`</a> | |
* <a href="#_topathvalue">`_.toPath`</a> | ||
* <a href="#_uniqueidprefix">`_.uniqueId`</a> | * <a href="#_uniqueidprefix">`_.uniqueId`</a> | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
## <a id="methods"></a>`Methods` | ## `Methods` | |
* <a href="#_templatesettingsimports_">`_.templateSettings.imports._`</a> | * <a href="#_templatesettingsimports_">`_.templateSettings.imports._`</a> | |
* <a href="#stringsizestring">`stringSize`</a> | ||
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
## <a id="properties"></a>`Properties` | ## `Properties` | |
* <a href="#_version">`_.VERSION`</a> | * <a href="#_version">`_.VERSION`</a> | |
* <a href="#_support">`_.support`</a> | ||
* <a href="#_supportargstag">`_.support.argsTag`</a> | ||
* <a href="#_supportenumerrorprops">`_.support.enumErrorProps`</a> | ||
* <a href="#_supportenumprototypes">`_.support.enumPrototypes`</a> | ||
* <a href="#_supportfuncdecomp">`_.support.funcDecomp`</a> | ||
* <a href="#_supportfuncnames">`_.support.funcNames`</a> | ||
* <a href="#_supportnodetag">`_.support.nodeTag`</a> | ||
* <a href="#_supportnonenumshadows">`_.support.nonEnumShadows`</a> | ||
* <a href="#_supportnonenumstrings">`_.support.nonEnumStrings`</a> | ||
* <a href="#_supportownlast">`_.support.ownLast`</a> | ||
* <a href="#_supportspliceobjects">`_.support.spliceObjects`</a> | ||
* <a href="#_supportunindexedchars">`_.support.unindexedChars`</a> | ||
* <a href="#_templatesettings">`_.templateSettings`</a> | * <a href="#_templatesettings">`_.templateSettings`</a> | |
* <a href="#_templatesettingsescape">`_.templateSettings.escape`</a> | * <a href="#_templatesettingsescape">`_.templateSettings.escape`</a> | |
* <a href="#_templatesettingsevaluate">`_.templateSettings.evaluate`</a> | * <a href="#_templatesettingsevaluate">`_.templateSettings.evaluate`</a> | |
* <a href="#_templatesettingsimports">`_.templateSettings.imports`</a> | * <a href="#_templatesettingsimports">`_.templateSettings.imports`</a> | |
* <a href="#_templatesettingsinterpolate">`_.templateSettings.interpolate`</a> | * <a href="#_templatesettingsinterpolate">`_.templateSettings.interpolate`</a> | |
* <a href="#_templatesettingsvariable">`_.templateSettings.variable`</a> | * <a href="#_templatesettingsvariable">`_.templateSettings.variable`</a> | |
<!-- /div --> | <!-- /div --> | |
<!-- /div --> | <!-- /div --> | |
<!-- div class="doc-container" --> | <!-- div class="doc-container" --> | |
<!-- div --> | <!-- div --> | |
## `“Array” Methods` | ## `“Array” Methods` | |
<!-- div --> | <!-- div --> | |
### <a id="_chunkarray-size1"></a>`_.chunk(array, [size=1])` | ### <a id="_chunkarray-size0"></a>`_.chunk(array, [size=0])` | |
<a href="#_chunkarray-size1">#</a> [Ⓢ](https://github.com/lodash/lodash/b | <a href="#_chunkarray-size0">#</a> [Ⓢ](https://github.com/lodash/lodash/b | |
lob/3.0.0/lodash.src.js#L4096 "View in source") [Ⓣ][1] | lob/4.0.0/lodash.js#L5250 "View in source") [Ⓣ][1] [Ⓝ](https://www | |
.npmjs.com/package/lodash.chunk "See the npm package") | ||
Creates an array of elements split into groups the length of `size`. | Creates an array of elements split into groups the length of `size`. | |
If `collection` can't be split evenly, the final chunk will be the remaining | If `array` can't be split evenly, the final chunk will be the remaining | |
elements. | elements. | |
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to process. | 1. `array` *(Array)*: The array to process. | |
2. `[size=1]` *(numer)*: The length of each chunk. | 2. `[size=0]` *(number)*: The length of each chunk. | |
#### Returns | #### Returns | |
*(Array)*: Returns the new array containing chunks. | *(Array)*: Returns the new array containing chunks. | |
#### Example | #### Example | |
```js | ```js | |
_.chunk(['a', 'b', 'c', 'd'], 2); | _.chunk(['a', 'b', 'c', 'd'], 2); | |
// => [['a', 'b'], ['c', 'd']] | // => [['a', 'b'], ['c', 'd']] | |
_.chunk(['a', 'b', 'c', 'd'], 3); | _.chunk(['a', 'b', 'c', 'd'], 3); | |
// => [['a', 'b', 'c'], ['d']] | // => [['a', 'b', 'c'], ['d']] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_compactarray"></a>`_.compact(array)` | ### <a id="_compactarray"></a>`_.compact(array)` | |
<a href="#_compactarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 3.0.0/lodash.src.js#L4127 "View in source") [Ⓣ][1] | <a href="#_compactarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 4.0.0/lodash.js#L5281 "View in source") [Ⓣ][1] [Ⓝ](https://www.npm js.com/package/lodash.compact "See the npm package") | |
Creates an array with all falsey values removed. The values `false`, `null`, | Creates an array with all falsey values removed. The values `false`, `null`, | |
`0`, `""`, `undefined`, and `NaN` are falsey. | `0`, `""`, `undefined`, and `NaN` are falsey. | |
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to compact. | 1. `array` *(Array)*: The array to compact. | |
#### Returns | #### Returns | |
*(Array)*: Returns the new array of filtered values. | *(Array)*: Returns the new array of filtered values. | |
skipping to change at line 358 | skipping to change at line 442 | |
```js | ```js | |
_.compact([0, 1, false, 2, '', 3]); | _.compact([0, 1, false, 2, '', 3]); | |
// => [1, 2, 3] | // => [1, 2, 3] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_concatarray-values"></a>`_.concat(array, [values])` | ||
<a href="#_concatarray-values">#</a> [Ⓢ](https://github.com/lodash/lodash | ||
/blob/4.0.0/lodash.js#L5317 "View in source") [Ⓣ][1] [Ⓝ](https://w | ||
ww.npmjs.com/package/lodash.concat "See the npm package") | ||
Creates a new array concatenating `array` with any additional arrays | ||
and/or values. | ||
#### Arguments | ||
1. `array` *(Array)*: The array to concatenate. | ||
2. `[values]` *(...*)*: The values to concatenate. | ||
#### Returns | ||
*(Array)*: Returns the new concatenated array. | ||
#### Example | ||
```js | ||
var array = [1]; | ||
var other = _.concat(array, 2, [3], [[4]]); | ||
console.log(other); | ||
// => [1, 2, 3, [4]] | ||
console.log(array); | ||
// => [1] | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_differencearray-values"></a>`_.difference(array, [values])` | ### <a id="_differencearray-values"></a>`_.difference(array, [values])` | |
<a href="#_differencearray-values">#</a> [Ⓢ](https://github.com/lodash/lo dash/blob/3.0.0/lodash.src.js#L4162 "View in source") [Ⓣ][1] | <a href="#_differencearray-values">#</a> [Ⓢ](https://github.com/lodash/lo dash/blob/4.0.0/lodash.js#L5338 "View in source") [Ⓣ][1] [Ⓝ](https ://www.npmjs.com/package/lodash.difference "See the npm package") | |
Creates an array excluding all values of the provided arrays using | Creates an array of unique `array` values not included in the other | |
`SameValueZero` for equality comparisons. | provided arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6 | |
*Note:** `SameValueZero` comparisons are like strict equality comparisons, | .0/#sec-samevaluezero) | |
e.g. `===`, except that `NaN` matches `NaN`. See the | for equality comparisons. | |
[ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezer | ||
o) | ||
for more details. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to inspect. | 1. `array` *(Array)*: The array to inspect. | |
2. `[values]` *(...Array)*: The arrays of values to exclude. | 2. `[values]` *(...Array)*: The values to exclude. | |
#### Returns | #### Returns | |
*(Array)*: Returns the new array of filtered values. | *(Array)*: Returns the new array of filtered values. | |
#### Example | #### Example | |
```js | ```js | |
_.difference([1, 2, 3], [5, 2, 10]); | _.difference([3, 2, 1], [4, 2]); | |
// => [1, 3] | // => [3, 1] | |
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_differencebyarray-values-iteratee_identity"></a>`_.differenceBy(arra | ||
y, [values], [iteratee=_.identity])` | ||
<a href="#_differencebyarray-values-iteratee_identity">#</a> [Ⓢ](https:// | ||
github.com/lodash/lodash/blob/4.0.0/lodash.js#L5365 "View in source") [Ⓣ] | ||
[1] [Ⓝ](https://www.npmjs.com/package/lodash.differenceby "See the npm pa | ||
ckage") | ||
This method is like `_.difference` except that it accepts `iteratee` which | ||
is invoked for each element of `array` and `values` to generate the criterion | ||
by which uniqueness is computed. The iteratee is invoked with one argument: (val | ||
ue). | ||
#### Arguments | ||
1. `array` *(Array)*: The array to inspect. | ||
2. `[values]` *(...Array)*: The values to exclude. | ||
3. `[iteratee=_.identity]` *(Function|Object|string)*: The iteratee invoked per | ||
element. | ||
#### Returns | ||
*(Array)*: Returns the new array of filtered values. | ||
#### Example | ||
```js | ||
_.differenceBy([3.1, 2.2, 1.3], [4.4, 2.5], Math.floor); | ||
// => [3.1, 1.3] | ||
// using the `_.property` iteratee shorthand | ||
_.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x'); | ||
// => [{ 'x': 2 }] | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_differencewitharray-values-comparator"></a>`_.differenceWith(array, | ||
[values], [comparator])` | ||
<a href="#_differencewitharray-values-comparator">#</a> [Ⓢ](https://githu | ||
b.com/lodash/lodash/blob/4.0.0/lodash.js#L5394 "View in source") [Ⓣ][1] [ | ||
Ⓝ](https://www.npmjs.com/package/lodash.differencewith "See the npm packa | ||
ge") | ||
This method is like `_.difference` except that it accepts `comparator` | ||
which is invoked to compare elements of `array` to `values`. The comparator | ||
is invoked with two arguments: (arrVal, othVal). | ||
#### Arguments | ||
1. `array` *(Array)*: The array to inspect. | ||
2. `[values]` *(...Array)*: The values to exclude. | ||
3. `[comparator]` *(Function)*: The comparator invoked per element. | ||
#### Returns | ||
*(Array)*: Returns the new array of filtered values. | ||
#### Example | ||
```js | ||
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; | ||
_.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual); | ||
// => [{ 'x': 2, 'y': 1 }] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_droparray-n1"></a>`_.drop(array, [n=1])` | ### <a id="_droparray-n1"></a>`_.drop(array, [n=1])` | |
<a href="#_droparray-n1">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 3.0.0/lodash.src.js#L4200 "View in source") [Ⓣ][1] | <a href="#_droparray-n1">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 4.0.0/lodash.js#L5428 "View in source") [Ⓣ][1] [Ⓝ](https://www.npm js.com/package/lodash.drop "See the npm package") | |
Creates a slice of `array` with `n` elements dropped from the beginning. | Creates a slice of `array` with `n` elements dropped from the beginning. | |
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to query. | 1. `array` *(Array)*: The array to query. | |
2. `[n=1]` *(number)*: The number of elements to drop. | 2. `[n=1]` *(number)*: The number of elements to drop. | |
#### Returns | #### Returns | |
*(Array)*: Returns the slice of `array`. | *(Array)*: Returns the slice of `array`. | |
skipping to change at line 419 | skipping to change at line 588 | |
_.drop([1, 2, 3], 0); | _.drop([1, 2, 3], 0); | |
// => [1, 2, 3] | // => [1, 2, 3] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_droprightarray-n1"></a>`_.dropRight(array, [n=1])` | ### <a id="_droprightarray-n1"></a>`_.dropRight(array, [n=1])` | |
<a href="#_droprightarray-n1">#</a> [Ⓢ](https://github.com/lodash/lodash/ blob/3.0.0/lodash.src.js#L4236 "View in source") [Ⓣ][1] | <a href="#_droprightarray-n1">#</a> [Ⓢ](https://github.com/lodash/lodash/ blob/4.0.0/lodash.js#L5461 "View in source") [Ⓣ][1] [Ⓝ](https://ww w.npmjs.com/package/lodash.dropright "See the npm package") | |
Creates a slice of `array` with `n` elements dropped from the end. | Creates a slice of `array` with `n` elements dropped from the end. | |
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to query. | 1. `array` *(Array)*: The array to query. | |
2. `[n=1]` *(number)*: The number of elements to drop. | 2. `[n=1]` *(number)*: The number of elements to drop. | |
#### Returns | #### Returns | |
*(Array)*: Returns the slice of `array`. | *(Array)*: Returns the slice of `array`. | |
skipping to change at line 450 | skipping to change at line 619 | |
_.dropRight([1, 2, 3], 0); | _.dropRight([1, 2, 3], 0); | |
// => [1, 2, 3] | // => [1, 2, 3] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_droprightwhilearray-predicate_identity-thisarg"></a>`_.dropRightWhil | ### <a id="_droprightwhilearray-predicate_identity"></a>`_.dropRightWhile(array, | |
e(array, [predicate=_.identity], [thisArg])` | [predicate=_.identity])` | |
<a href="#_droprightwhilearray-predicate_identity-thisarg">#</a> [Ⓢ](http | <a href="#_droprightwhilearray-predicate_identity">#</a> [Ⓢ](https://gith | |
s://github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L4288 "View in source") [& | ub.com/lodash/lodash/blob/4.0.0/lodash.js#L5505 "View in source") [Ⓣ][1] | |
#x24C9;][1] | [Ⓝ](https://www.npmjs.com/package/lodash.droprightwhile "See the npm pack | |
age") | ||
Creates a slice of `array` excluding elements dropped from the end. | Creates a slice of `array` excluding elements dropped from the end. | |
Elements are dropped until `predicate` returns falsey. The predicate is | Elements are dropped until `predicate` returns falsey. The predicate is | |
bound to `thisArg` and invoked with three arguments; (value, index, array). | invoked with three arguments: (value, index, array). | |
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to query. | 1. `array` *(Array)*: The array to query. | |
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | |
element. | iteration. | |
3. `[thisArg]` *(*)*: The `this` binding of `predicate`. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the slice of `array`. | *(Array)*: Returns the slice of `array`. | |
#### Example | #### Example | |
```js | ```js | |
_.dropRightWhile([1, 2, 3], function(n) { return n > 1; }); | ||
// => [1] | ||
var users = [ | var users = [ | |
{ 'user': 'barney', 'status': 'busy', 'active': false }, | { 'user': 'barney', 'active': true }, | |
{ 'user': 'fred', 'status': 'busy', 'active': true }, | { 'user': 'fred', 'active': false }, | |
{ 'user': 'pebbles', 'status': 'away', 'active': true } | { 'user': 'pebbles', 'active': false } | |
]; | ]; | |
// using the "_.property" callback shorthand | _.dropRightWhile(users, function(o) { return !o.active; }); | |
_.pluck(_.dropRightWhile(users, 'active'), 'user'); | // => objects for ['barney'] | |
// => ['barney'] | ||
// using the "_.matches" callback shorthand | // using the `_.matches` iteratee shorthand | |
_.pluck(_.dropRightWhile(users, { 'status': 'away' }), 'user'); | _.dropRightWhile(users, { 'user': 'pebbles', 'active': false }); | |
// => ['barney', 'fred'] | // => objects for ['barney', 'fred'] | |
// using the `_.matchesProperty` iteratee shorthand | ||
_.dropRightWhile(users, ['active', false]); | ||
// => objects for ['barney'] | ||
// using the `_.property` iteratee shorthand | ||
_.dropRightWhile(users, 'active'); | ||
// => objects for ['barney', 'fred', 'pebbles'] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_dropwhilearray-predicate_identity-thisarg"></a>`_.dropWhile(array, [ | ### <a id="_dropwhilearray-predicate_identity"></a>`_.dropWhile(array, [predicat | |
predicate=_.identity], [thisArg])` | e=_.identity])` | |
<a href="#_dropwhilearray-predicate_identity-thisarg">#</a> [Ⓢ](https://g | <a href="#_dropwhilearray-predicate_identity">#</a> [Ⓢ](https://github.co | |
ithub.com/lodash/lodash/blob/3.0.0/lodash.src.js#L4338 "View in source") [Ɍ | m/lodash/lodash/blob/4.0.0/lodash.js#L5545 "View in source") [Ⓣ][1] [ | |
9;][1] | 4C3;](https://www.npmjs.com/package/lodash.dropwhile "See the npm package") | |
Creates a slice of `array` excluding elements dropped from the beginning. | Creates a slice of `array` excluding elements dropped from the beginning. | |
Elements are dropped until `predicate` returns falsey. The predicate is | Elements are dropped until `predicate` returns falsey. The predicate is | |
bound to `thisArg` and invoked with three arguments; (value, index, array). | invoked with three arguments: (value, index, array). | |
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to query. | 1. `array` *(Array)*: The array to query. | |
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | |
element. | iteration. | |
3. `[thisArg]` *(*)*: The `this` binding of `predicate`. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the slice of `array`. | *(Array)*: Returns the slice of `array`. | |
#### Example | #### Example | |
```js | ```js | |
_.dropWhile([1, 2, 3], function(n) { return n < 3; }); | ||
// => [3] | ||
var users = [ | var users = [ | |
{ 'user': 'barney', 'status': 'busy', 'active': true }, | { 'user': 'barney', 'active': false }, | |
{ 'user': 'fred', 'status': 'busy', 'active': false }, | { 'user': 'fred', 'active': false }, | |
{ 'user': 'pebbles', 'status': 'away', 'active': true } | { 'user': 'pebbles', 'active': true } | |
]; | ]; | |
// using the "_.property" callback shorthand | _.dropWhile(users, function(o) { return !o.active; }); | |
_.pluck(_.dropWhile(users, 'active'), 'user'); | // => objects for ['pebbles'] | |
// => ['fred', 'pebbles'] | ||
// using the `_.matches` iteratee shorthand | ||
_.dropWhile(users, { 'user': 'barney', 'active': false }); | ||
// => objects for ['fred', 'pebbles'] | ||
// using the "_.matches" callback shorthand | // using the `_.matchesProperty` iteratee shorthand | |
_.pluck(_.dropWhile(users, { 'status': 'busy' }), 'user'); | _.dropWhile(users, ['active', false]); | |
// => ['pebbles'] | // => objects for ['pebbles'] | |
// using the `_.property` iteratee shorthand | ||
_.dropWhile(users, 'active'); | ||
// => objects for ['barney', 'fred', 'pebbles'] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_findindexarray-predicate_identity-thisarg"></a>`_.findIndex(array, [ | ### <a id="_fillarray-value-start0-endarraylength"></a>`_.fill(array, value, [st | |
predicate=_.identity], [thisArg])` | art=0], [end=array.length])` | |
<a href="#_findindexarray-predicate_identity-thisarg">#</a> [Ⓢ](https://g | <a href="#_fillarray-value-start0-endarraylength">#</a> [Ⓢ](https://githu | |
ithub.com/lodash/lodash/blob/3.0.0/lodash.src.js#L4388 "View in source") [Ɍ | b.com/lodash/lodash/blob/4.0.0/lodash.js#L5579 "View in source") [Ⓣ][1] [ | |
9;][1] | Ⓝ](https://www.npmjs.com/package/lodash.fill "See the npm package") | |
This method is like `_.find` except that it returns the index of the first | Fills elements of `array` with `value` from `start` up to, but not | |
element `predicate` returns truthy for, instead of the element itself. | including, `end`. | |
<br> | ||
<br> | ||
**Note:** This method mutates `array`. | ||
#### Arguments | ||
1. `array` *(Array)*: The array to fill. | ||
2. `value` *(*)*: The value to fill `array` with. | ||
3. `[start=0]` *(number)*: The start position. | ||
4. `[end=array.length]` *(number)*: The end position. | ||
#### Returns | ||
*(Array)*: Returns `array`. | ||
#### Example | ||
```js | ||
var array = [1, 2, 3]; | ||
_.fill(array, 'a'); | ||
console.log(array); | ||
// => ['a', 'a', 'a'] | ||
_.fill(Array(3), 2); | ||
// => [2, 2, 2] | ||
_.fill([4, 6, 8, 10], '*', 1, 3); | ||
// => [4, '*', '*', 10] | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
If a property name is provided for `predicate` the created "_.property" | ### <a id="_findindexarray-predicate_identity"></a>`_.findIndex(array, [predicat | |
style callback returns the property value of the given element. | e=_.identity])` | |
<a href="#_findindexarray-predicate_identity">#</a> [Ⓢ](https://github.co | ||
m/lodash/lodash/blob/4.0.0/lodash.js#L5624 "View in source") [Ⓣ][1] [ | ||
4C3;](https://www.npmjs.com/package/lodash.findindex "See the npm package") | ||
If an object is provided for `predicate` the created "_.matches" style | This method is like `_.find` except that it returns the index of the first | |
callback returns `true` for elements that have the properties of the given | element `predicate` returns truthy for instead of the element itself. | |
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to search. | 1. `array` *(Array)*: The array to search. | |
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | |
iteration. If a property name or object is provided it is used to create a "_.p | iteration. | |
roperty" or "_.matches" style callback respectively. | ||
3. `[thisArg]` *(*)*: The `this` binding of `predicate`. | ||
#### Returns | #### Returns | |
*(number)*: Returns the index of the found element, else `-1`. | *(number)*: Returns the index of the found element, else `-1`. | |
#### Example | #### Example | |
```js | ```js | |
var users = [ | var users = [ | |
{ 'user': 'barney', 'age': 36, 'active': false }, | { 'user': 'barney', 'active': false }, | |
{ 'user': 'fred', 'age': 40, 'active': true }, | { 'user': 'fred', 'active': false }, | |
{ 'user': 'pebbles', 'age': 1, 'active': false } | { 'user': 'pebbles', 'active': true } | |
]; | ]; | |
_.findIndex(users, function(chr) { return chr.age < 40; }); | _.findIndex(users, function(o) { return o.user == 'barney'; }); | |
// => 0 | // => 0 | |
// using the "_.matches" callback shorthand | // using the `_.matches` iteratee shorthand | |
_.findIndex(users, { 'age': 1 }); | _.findIndex(users, { 'user': 'fred', 'active': false }); | |
// => 2 | // => 1 | |
// using the `_.matchesProperty` iteratee shorthand | ||
_.findIndex(users, ['active', false]); | ||
// => 0 | ||
// using the "_.property" callback shorthand | // using the `_.property` iteratee shorthand | |
_.findIndex(users, 'active'); | _.findIndex(users, 'active'); | |
// => 1 | // => 2 | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_findlastindexarray-predicate_identity-thisarg"></a>`_.findLastIndex( | ### <a id="_findlastindexarray-predicate_identity"></a>`_.findLastIndex(array, [ | |
array, [predicate=_.identity], [thisArg])` | predicate=_.identity])` | |
<a href="#_findlastindexarray-predicate_identity-thisarg">#</a> [Ⓢ](https | <a href="#_findlastindexarray-predicate_identity">#</a> [Ⓢ](https://githu | |
://github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L4440 "View in source") [&# | b.com/lodash/lodash/blob/4.0.0/lodash.js#L5663 "View in source") [Ⓣ][1] [ | |
x24C9;][1] | Ⓝ](https://www.npmjs.com/package/lodash.findlastindex "See the npm packag | |
e") | ||
This method is like `_.findIndex` except that it iterates over elements | This method is like `_.findIndex` except that it iterates over elements | |
of `collection` from right to left. | of `collection` from right to left. | |
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to search. | 1. `array` *(Array)*: The array to search. | |
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | |
iteration. If a property name or object is provided it is used to create a "_.p | iteration. | |
roperty" or "_.matches" style callback respectively. | ||
3. `[thisArg]` *(*)*: The `this` binding of `predicate`. | ||
#### Returns | #### Returns | |
*(number)*: Returns the index of the found element, else `-1`. | *(number)*: Returns the index of the found element, else `-1`. | |
#### Example | #### Example | |
```js | ```js | |
var users = [ | var users = [ | |
{ 'user': 'barney', 'age': 36, 'active': true }, | { 'user': 'barney', 'active': true }, | |
{ 'user': 'fred', 'age': 40, 'active': false }, | { 'user': 'fred', 'active': false }, | |
{ 'user': 'pebbles', 'age': 1, 'active': false } | { 'user': 'pebbles', 'active': false } | |
]; | ]; | |
_.findLastIndex(users, function(chr) { return chr.age < 40; }); | _.findLastIndex(users, function(o) { return o.user == 'pebbles'; }); | |
// => 2 | // => 2 | |
// using the "_.matches" callback shorthand | // using the `_.matches` iteratee shorthand | |
_.findLastIndex(users, { 'age': 40 }); | _.findLastIndex(users, { 'user': 'barney', 'active': true }); | |
// => 1 | // => 0 | |
// using the `_.matchesProperty` iteratee shorthand | ||
_.findLastIndex(users, ['active', false]); | ||
// => 2 | ||
// using the "_.property" callback shorthand | // using the `_.property` iteratee shorthand | |
_.findLastIndex(users, 'active'); | _.findLastIndex(users, 'active'); | |
// => 0 | // => 0 | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_firstarray"></a>`_.first(array)` | ### <a id="_flatmaparray-iteratee_identity"></a>`_.flatMap(array, [iteratee=_.id | |
<a href="#_firstarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3. | entity])` | |
0.0/lodash.src.js#L4468 "View in source") [Ⓣ][1] | <a href="#_flatmaparray-iteratee_identity">#</a> [Ⓢ](https://github.com/l | |
odash/lodash/blob/4.0.0/lodash.js#L5689 "View in source") [Ⓣ][1] [Ⓝ | ||
;](https://www.npmjs.com/package/lodash.flatmap "See the npm package") | ||
Gets the first element of `array`. | Creates an array of flattened values by running each element in `array` | |
through `iteratee` and concating its result to the other mapped values. | ||
The iteratee is invoked with three arguments: (value, index|key, array). | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to query. | 1. `array` *(Array)*: The array to iterate over. | |
2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per | ||
iteration. | ||
#### Returns | #### Returns | |
*(*)*: Returns the first element of `array`. | *(Array)*: Returns the new array. | |
#### Example | #### Example | |
```js | ```js | |
_.first([1, 2, 3]); | function duplicate(n) { | |
// => 1 | return [n, n]; | |
} | ||
_.first([]); | _.flatMap([1, 2], duplicate); | |
// => undefined | // => [1, 1, 2, 2] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_flattenarray-isdeep"></a>`_.flatten(array, [isDeep])` | ### <a id="_flattenarray"></a>`_.flatten(array)` | |
<a href="#_flattenarray-isdeep">#</a> [Ⓢ](https://github.com/lodash/lodas | <a href="#_flattenarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ | |
h/blob/3.0.0/lodash.src.js#L4492 "View in source") [Ⓣ][1] | 4.0.0/lodash.js#L5707 "View in source") [Ⓣ][1] [Ⓝ](https://www.npm | |
js.com/package/lodash.flatten "See the npm package") | ||
Flattens a nested array. If `isDeep` is `true` the array is recursively | Flattens `array` a single level. | |
flattened, otherwise it is only flattened a single level. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to flatten. | 1. `array` *(Array)*: The array to flatten. | |
2. `[isDeep]` *(boolean)*: Specify a deep flatten. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the new flattened array. | *(Array)*: Returns the new flattened array. | |
#### Example | #### Example | |
```js | ```js | |
_.flatten([1, [2], [3, [[4]]]]); | _.flatten([1, [2, 3, [4]]]); | |
// => [1, 2, 3, [[4]]]; | // => [1, 2, 3, [4]] | |
// using `isDeep` | ||
_.flatten([1, [2], [3, [[4]]]], true); | ||
// => [1, 2, 3, 4]; | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_flattendeeparray"></a>`_.flattenDeep(array)` | ### <a id="_flattendeeparray"></a>`_.flattenDeep(array)` | |
<a href="#_flattendeeparray">#</a> [Ⓢ](https://github.com/lodash/lodash/b lob/3.0.0/lodash.src.js#L4513 "View in source") [Ⓣ][1] | <a href="#_flattendeeparray">#</a> [Ⓢ](https://github.com/lodash/lodash/b lob/4.0.0/lodash.js#L5725 "View in source") [Ⓣ][1] [Ⓝ](https://www .npmjs.com/package/lodash.flattendeep "See the npm package") | |
Recursively flattens a nested array. | This method is like `_.flatten` except that it recursively flattens `array`. | |
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to recursively flatten. | 1. `array` *(Array)*: The array to recursively flatten. | |
#### Returns | #### Returns | |
*(Array)*: Returns the new flattened array. | *(Array)*: Returns the new flattened array. | |
#### Example | #### Example | |
```js | ```js | |
_.flattenDeep([1, [2], [3, [[4]]]]); | _.flattenDeep([1, [2, 3, [4]]]); | |
// => [1, 2, 3, 4]; | // => [1, 2, 3, 4] | |
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_frompairspairs"></a>`_.fromPairs(pairs)` | ||
<a href="#_frompairspairs">#</a> [Ⓢ](https://github.com/lodash/lodash/blo | ||
b/4.0.0/lodash.js#L5744 "View in source") [Ⓣ][1] [Ⓝ](https://www.n | ||
pmjs.com/package/lodash.frompairs "See the npm package") | ||
The inverse of `_.toPairs`; this method returns an object composed | ||
from key-value `pairs`. | ||
#### Arguments | ||
1. `pairs` *(Array)*: The key-value pairs. | ||
#### Returns | ||
*(Object)*: Returns the new object. | ||
#### Example | ||
```js | ||
_.fromPairs([['fred', 30], ['barney', 40]]); | ||
// => { 'fred': 30, 'barney': 40 } | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_headarray"></a>`_.head(array)` | ||
<a href="#_headarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4.0 | ||
.0/lodash.js#L5773 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs. | ||
com/package/lodash.head "See the npm package") | ||
Gets the first element of `array`. | ||
#### Aliases | ||
*_.first* | ||
#### Arguments | ||
1. `array` *(Array)*: The array to query. | ||
#### Returns | ||
*(*)*: Returns the first element of `array`. | ||
#### Example | ||
```js | ||
_.head([1, 2, 3]); | ||
// => 1 | ||
_.head([]); | ||
// => undefined | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_indexofarray-value-fromindex0"></a>`_.indexOf(array, value, [fromInd ex=0])` | ### <a id="_indexofarray-value-fromindex0"></a>`_.indexOf(array, value, [fromInd ex=0])` | |
<a href="#_indexofarray-value-fromindex0">#</a> [Ⓢ](https://github.com/lo dash/lodash/blob/3.0.0/lodash.src.js#L4550 "View in source") [Ⓣ][1] | <a href="#_indexofarray-value-fromindex0">#</a> [Ⓢ](https://github.com/lo dash/lodash/blob/4.0.0/lodash.js#L5800 "View in source") [Ⓣ][1] [Ⓝ ](https://www.npmjs.com/package/lodash.indexof "See the npm package") | |
Gets the index at which the first occurrence of `value` is found in `array` | Gets the index at which the first occurrence of `value` is found in `array` | |
using `SameValueZero` for equality comparisons. If `fromIndex` is negative, | using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevalu | |
it is used as the offset from the end of `array`. If `array` is sorted | ezero) | |
providing `true` for `fromIndex` performs a faster binary search. | for equality comparisons. If `fromIndex` is negative, it's used as the offset | |
*Note:** `SameValueZero` comparisons are like strict equality comparisons, | from the end of `array`. If `array` is sorted providing `true` for `fromIndex` | |
e.g. `===`, except that `NaN` matches `NaN`. See the | performs a faster binary search. | |
[ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezer | ||
o) | ||
for more details. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to search. | 1. `array` *(Array)*: The array to search. | |
2. `value` *(*)*: The value to search for. | 2. `value` *(*)*: The value to search for. | |
3. `[fromIndex=0]` *(boolean|number)*: The index to search from or `true` to per form a binary search on a sorted array. | 3. `[fromIndex=0]` *(number)*: The index to search from. | |
#### Returns | #### Returns | |
*(number)*: Returns the index of the matched value, else `-1`. | *(number)*: Returns the index of the matched value, else `-1`. | |
#### Example | #### Example | |
```js | ```js | |
_.indexOf([1, 2, 3, 1, 2, 3], 2); | _.indexOf([1, 2, 1, 2], 2); | |
// => 1 | // => 1 | |
// using `fromIndex` | // using `fromIndex` | |
_.indexOf([1, 2, 3, 1, 2, 3], 2, 3); | _.indexOf([1, 2, 1, 2], 2, 2); | |
// => 4 | // => 3 | |
// performing a binary search | ||
_.indexOf([4, 4, 5, 5, 6, 6], 5, true); | ||
// => 2 | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_initialarray"></a>`_.initial(array)` | ### <a id="_initialarray"></a>`_.initial(array)` | |
<a href="#_initialarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 3.0.0/lodash.src.js#L4579 "View in source") [Ⓣ][1] | <a href="#_initialarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 4.0.0/lodash.js#L5825 "View in source") [Ⓣ][1] [Ⓝ](https://www.npm js.com/package/lodash.initial "See the npm package") | |
Gets all but the last element of `array`. | Gets all but the last element of `array`. | |
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to query. | 1. `array` *(Array)*: The array to query. | |
#### Returns | #### Returns | |
*(Array)*: Returns the slice of `array`. | *(Array)*: Returns the slice of `array`. | |
#### Example | #### Example | |
skipping to change at line 773 | skipping to change at line 1006 | |
_.initial([1, 2, 3]); | _.initial([1, 2, 3]); | |
// => [1, 2] | // => [1, 2] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_intersectionarrays"></a>`_.intersection([arrays])` | ### <a id="_intersectionarrays"></a>`_.intersection([arrays])` | |
<a href="#_intersectionarrays">#</a> [Ⓢ](https://github.com/lodash/lodash /blob/3.0.0/lodash.src.js#L4602 "View in source") [Ⓣ][1] | <a href="#_intersectionarrays">#</a> [Ⓢ](https://github.com/lodash/lodash /blob/4.0.0/lodash.js#L5843 "View in source") [Ⓣ][1] [Ⓝ](https://w ww.npmjs.com/package/lodash.intersection "See the npm package") | |
Creates an array of unique values in all provided arrays using `SameValueZero` | Creates an array of unique values that are included in all of the provided | |
arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-s | ||
amevaluezero) | ||
for equality comparisons. | for equality comparisons. | |
*Note:** `SameValueZero` comparisons are like strict equality comparisons, | ||
e.g. `===`, except that `NaN` matches `NaN`. See the | ||
[ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezer | ||
o) | ||
for more details. | ||
#### Arguments | #### Arguments | |
1. `[arrays]` *(...Array)*: The arrays to inspect. | 1. `[arrays]` *(...Array)*: The arrays to inspect. | |
#### Returns | #### Returns | |
*(Array)*: Returns the new array of shared values. | *(Array)*: Returns the new array of shared values. | |
#### Example | #### Example | |
```js | ```js | |
_.intersection([1, 2, 3], [5, 2, 1, 4], [2, 1]); | _.intersection([2, 1], [4, 2], [1, 2]); | |
// => [1, 2] | // => [2] | |
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_intersectionbyarrays-iteratee_identity"></a>`_.intersectionBy([array | ||
s], [iteratee=_.identity])` | ||
<a href="#_intersectionbyarrays-iteratee_identity">#</a> [Ⓢ](https://gith | ||
ub.com/lodash/lodash/blob/4.0.0/lodash.js#L5870 "View in source") [Ⓣ][1] | ||
[Ⓝ](https://www.npmjs.com/package/lodash.intersectionby "See the npm pack | ||
age") | ||
This method is like `_.intersection` except that it accepts `iteratee` | ||
which is invoked for each element of each `arrays` to generate the criterion | ||
by which uniqueness is computed. The iteratee is invoked with one argument: (val | ||
ue). | ||
#### Arguments | ||
1. `[arrays]` *(...Array)*: The arrays to inspect. | ||
2. `[iteratee=_.identity]` *(Function|Object|string)*: The iteratee invoked per | ||
element. | ||
#### Returns | ||
*(Array)*: Returns the new array of shared values. | ||
#### Example | ||
```js | ||
_.intersectionBy([2.1, 1.2], [4.3, 2.4], Math.floor); | ||
// => [2.1] | ||
// using the `_.property` iteratee shorthand | ||
_.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); | ||
// => [{ 'x': 1 }] | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_intersectionwitharrays-comparator"></a>`_.intersectionWith([arrays], | ||
[comparator])` | ||
<a href="#_intersectionwitharrays-comparator">#</a> [Ⓢ](https://github.co | ||
m/lodash/lodash/blob/4.0.0/lodash.js#L5903 "View in source") [Ⓣ][1] [ | ||
4C3;](https://www.npmjs.com/package/lodash.intersectionwith "See the npm package | ||
") | ||
This method is like `_.intersection` except that it accepts `comparator` | ||
which is invoked to compare elements of `arrays`. The comparator is invoked | ||
with two arguments: (arrVal, othVal). | ||
#### Arguments | ||
1. `[arrays]` *(...Array)*: The arrays to inspect. | ||
2. `[comparator]` *(Function)*: The comparator invoked per element. | ||
#### Returns | ||
*(Array)*: Returns the new array of shared values. | ||
#### Example | ||
```js | ||
var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; | ||
var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; | ||
_.intersectionWith(objects, others, _.isEqual); | ||
// => [{ 'x': 1, 'y': 2 }] | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_joinarray-separator-"></a>`_.join(array, [separator=','])` | ||
<a href="#_joinarray-separator-">#</a> [Ⓢ](https://github.com/lodash/loda | ||
sh/blob/4.0.0/lodash.js#L5931 "View in source") [Ⓣ][1] [Ⓝ](https:/ | ||
/www.npmjs.com/package/lodash.join "See the npm package") | ||
Converts all elements in `array` into a string separated by `separator`. | ||
#### Arguments | ||
1. `array` *(Array)*: The array to convert. | ||
2. `[separator=',']` *(string)*: The element separator. | ||
#### Returns | ||
*(string)*: Returns the joined string. | ||
#### Example | ||
```js | ||
_.join(['a', 'b', 'c'], '~'); | ||
// => 'a~b~c' | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_lastarray"></a>`_.last(array)` | ### <a id="_lastarray"></a>`_.last(array)` | |
<a href="#_lastarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.0 .0/lodash.src.js#L4657 "View in source") [Ⓣ][1] | <a href="#_lastarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4.0 .0/lodash.js#L5948 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs. com/package/lodash.last "See the npm package") | |
Gets the last element of `array`. | Gets the last element of `array`. | |
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to query. | 1. `array` *(Array)*: The array to query. | |
#### Returns | #### Returns | |
*(*)*: Returns the last element of `array`. | *(*)*: Returns the last element of `array`. | |
#### Example | #### Example | |
```js | ```js | |
_.last([1, 2, 3]); | _.last([1, 2, 3]); | |
// => 3 | // => 3 | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_lastindexofarray-value"></a>`_.lastIndexOf(array, value)` | ### <a id="_lastindexofarray-value-fromindexarraylength-1"></a>`_.lastIndexOf(ar | |
<a href="#_lastindexofarray-value">#</a> [Ⓢ](https://github.com/lodash/lo | ray, value, [fromIndex=array.length-1])` | |
dash/blob/3.0.0/lodash.src.js#L4687 "View in source") [Ⓣ][1] | <a href="#_lastindexofarray-value-fromindexarraylength-1">#</a> [Ⓢ](https | |
://github.com/lodash/lodash/blob/4.0.0/lodash.js#L5973 "View in source") [Ɍ | ||
9;][1] [Ⓝ](https://www.npmjs.com/package/lodash.lastindexof "See the npm | ||
package") | ||
This method is like `_.indexOf` except that it iterates over elements of | This method is like `_.indexOf` except that it iterates over elements of | |
`array` from right to left. | `array` from right to left. | |
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to search. | 1. `array` *(Array)*: The array to search. | |
2. `value` *(*)*: The value to search for. | 2. `value` *(*)*: The value to search for. | |
3. `[fromIndex=array.length-1]` *(boolean|number)*: The index to search from or `true` to perform a binary search on a sorted array. | 3. `[fromIndex=array.length-1]` *(number)*: The index to search from. | |
#### Returns | #### Returns | |
*(number)*: Returns the index of the matched value, else `-1`. | *(number)*: Returns the index of the matched value, else `-1`. | |
#### Example | #### Example | |
```js | ```js | |
_.lastIndexOf([1, 2, 3, 1, 2, 3], 2); | _.lastIndexOf([1, 2, 1, 2], 2); | |
// => 4 | // => 3 | |
// using `fromIndex` | // using `fromIndex` | |
_.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3); | _.lastIndexOf([1, 2, 1, 2], 2, 2); | |
// => 1 | // => 1 | |
// performing a binary search | ||
_.lastIndexOf([4, 4, 5, 5, 6, 6], 5, true); | ||
// => 3 | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_pullarray-values"></a>`_.pull(array, [values])` | ### <a id="_pullarray-values"></a>`_.pull(array, [values])` | |
<a href="#_pullarray-values">#</a> [Ⓢ](https://github.com/lodash/lodash/b lob/3.0.0/lodash.src.js#L4734 "View in source") [Ⓣ][1] | <a href="#_pullarray-values">#</a> [Ⓢ](https://github.com/lodash/lodash/b lob/4.0.0/lodash.js#L6015 "View in source") [Ⓣ][1] [Ⓝ](https://www .npmjs.com/package/lodash.pull "See the npm package") | |
Removes all provided values from `array` using `SameValueZero` for equality | Removes all provided values from `array` using | |
comparisons. | [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) | |
*Notes:** | for equality comparisons. | |
- Unlike `_.without`, this method mutates `array`. | <br> | |
- `SameValueZero` comparisons are like strict equality comparisons, e.g. `===`, | <br> | |
except that `NaN` matches `NaN`. See the [ES spec](https://people.mozilla.org/~j | **Note:** Unlike `_.without`, this method mutates `array`. | |
orendorff/es6-draft.html#sec-samevaluezero) | ||
for more details. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to modify. | 1. `array` *(Array)*: The array to modify. | |
2. `[values]` *(...*)*: The values to remove. | 2. `[values]` *(...*)*: The values to remove. | |
#### Returns | #### Returns | |
*(Array)*: Returns `array`. | *(Array)*: Returns `array`. | |
#### Example | #### Example | |
```js | ```js | |
var array = [1, 2, 3, 1, 2, 3]; | var array = [1, 2, 3, 1, 2, 3]; | |
_.pull(array, 2, 3); | _.pull(array, 2, 3); | |
console.log(array); | console.log(array); | |
// => [1, 1] | // => [1, 1] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_pullatarray-indexes"></a>`_.pullAt(array, [indexes])` | ### <a id="_pullallarray-values"></a>`_.pullAll(array, values)` | |
<a href="#_pullatarray-indexes">#</a> [Ⓢ](https://github.com/lodash/lodas | <a href="#_pullallarray-values">#</a> [Ⓢ](https://github.com/lodash/lodas | |
h/blob/3.0.0/lodash.src.js#L4779 "View in source") [Ⓣ][1] | h/blob/4.0.0/lodash.js#L6036 "View in source") [Ⓣ][1] [Ⓝ](https:// | |
www.npmjs.com/package/lodash.pullall "See the npm package") | ||
Removes elements from `array` corresponding to the given indexes and returns | This method is like `_.pull` except that it accepts an array of values to remove | |
an array of the removed elements. Indexes may be specified as an array of | . | |
indexes or as individual arguments. | <br> | |
*Note:** Unlike `_.at`, this method mutates `array`. | <br> | |
**Note:** Unlike `_.difference`, this method mutates `array`. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to modify. | 1. `array` *(Array)*: The array to modify. | |
2. `[indexes]` *(...(number|number[])*: The indexes of elements to remov e, specified as individual indexes or arrays of indexes. | 2. `values` *(Array)*: The values to remove. | |
#### Returns | #### Returns | |
*(Array)*: Returns the new array of removed elements. | *(Array)*: Returns `array`. | |
#### Example | #### Example | |
```js | ```js | |
var array = [5, 10, 15, 20]; | var array = [1, 2, 3, 1, 2, 3]; | |
var evens = _.pullAt(array, [1, 3]); | ||
_.pull(array, [2, 3]); | ||
console.log(array); | console.log(array); | |
// => [5, 15] | // => [1, 1] | |
console.log(evens); | ||
// => [10, 20] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_removearray-predicate_identity-thisarg"></a>`_.remove(array, [predic | ### <a id="_pullallbyarray-values-iteratee_identity"></a>`_.pullAllBy(array, val | |
ate=_.identity], [thisArg])` | ues, [iteratee=_.identity])` | |
<a href="#_removearray-predicate_identity-thisarg">#</a> [Ⓢ](https://gith | <a href="#_pullallbyarray-values-iteratee_identity">#</a> [Ⓢ](https://git | |
ub.com/lodash/lodash/blob/3.0.0/lodash.src.js#L4817 "View in source") [Ⓣ] | hub.com/lodash/lodash/blob/4.0.0/lodash.js#L6064 "View in source") [Ⓣ][1] | |
[1] | [Ⓝ](https://www.npmjs.com/package/lodash.pullallby "See the npm package" | |
) | ||
Removes all elements from `array` that `predicate` returns truthy for | This method is like `_.pullAll` except that it accepts `iteratee` which is | |
and returns an array of the removed elements. The predicate is bound to | invoked for each element of `array` and `values` to to generate the criterion | |
`thisArg` and invoked with three arguments; (value, index, array). | by which uniqueness is computed. The iteratee is invoked with one argument: (val | |
ue). | ||
<br> | ||
<br> | ||
**Note:** Unlike `_.differenceBy`, this method mutates `array`. | ||
#### Arguments | ||
1. `array` *(Array)*: The array to modify. | ||
2. `values` *(Array)*: The values to remove. | ||
3. `[iteratee=_.identity]` *(Function|Object|string)*: The iteratee invoked per | ||
element. | ||
#### Returns | ||
*(Array)*: Returns `array`. | ||
If a property name is provided for `predicate` the created "_.property" | #### Example | |
style callback returns the property value of the given element. | ```js | |
var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }]; | ||
If an object is provided for `predicate` the created "_.matches" style | _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x'); | |
callback returns `true` for elements that have the properties of the given | console.log(array); | |
object, else `false`. | // => [{ 'x': 2 }] | |
*Note:** Unlike `_.filter`, this method mutates `array`. | ``` | |
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_pullatarray-indexes"></a>`_.pullAt(array, [indexes])` | ||
<a href="#_pullatarray-indexes">#</a> [Ⓢ](https://github.com/lodash/lodas | ||
h/blob/4.0.0/lodash.js#L6094 "View in source") [Ⓣ][1] [Ⓝ](https:// | ||
www.npmjs.com/package/lodash.pullat "See the npm package") | ||
Removes elements from `array` corresponding to `indexes` and returns an | ||
array of removed elements. | ||
<br> | ||
<br> | ||
**Note:** Unlike `_.at`, this method mutates `array`. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to modify. | 1. `array` *(Array)*: The array to modify. | |
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `[indexes]` *(...(number|number[])*: The indexes of elements to remov | |
iteration. If a property name or object is provided it is used to create a "_.p | e, specified individually or in arrays. | |
roperty" or "_.matches" style callback respectively. | ||
3. `[thisArg]` *(*)*: The `this` binding of `predicate`. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the new array of removed elements. | *(Array)*: Returns the new array of removed elements. | |
#### Example | #### Example | |
```js | ```js | |
var array = [1, 2, 3, 4]; | var array = [5, 10, 15, 20]; | |
var evens = _.remove(array, function(n) { return n % 2 == 0; }); | var evens = _.pullAt(array, 1, 3); | |
console.log(array); | console.log(array); | |
// => [1, 3] | // => [5, 15] | |
console.log(evens); | console.log(evens); | |
// => [2, 4] | // => [10, 20] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_restarray"></a>`_.rest(array)` | ### <a id="_removearray-predicate_identity"></a>`_.remove(array, [predicate=_.id | |
<a href="#_restarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.0 | entity])` | |
.0/lodash.src.js#L4848 "View in source") [Ⓣ][1] | <a href="#_removearray-predicate_identity">#</a> [Ⓢ](https://github.com/l | |
odash/lodash/blob/4.0.0/lodash.js#L6128 "View in source") [Ⓣ][1] [Ⓝ | ||
;](https://www.npmjs.com/package/lodash.remove "See the npm package") | ||
Gets all but the first element of `array`. | Removes all elements from `array` that `predicate` returns truthy for | |
and returns an array of the removed elements. The predicate is invoked with | ||
three arguments: (value, index, array). | ||
<br> | ||
<br> | ||
**Note:** Unlike `_.filter`, this method mutates `array`. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to query. | 1. `array` *(Array)*: The array to modify. | |
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | ||
iteration. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the slice of `array`. | *(Array)*: Returns the new array of removed elements. | |
#### Example | #### Example | |
```js | ```js | |
_.rest([1, 2, 3]); | var array = [1, 2, 3, 4]; | |
// => [2, 3] | var evens = _.remove(array, function(n) { | |
return n % 2 == 0; | ||
}); | ||
console.log(array); | ||
// => [1, 3] | ||
console.log(evens); | ||
// => [2, 4] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_slicearray-start0"></a>`_.slice(array, [start=0])` | ### <a id="_slicearray-start0-endarraylength"></a>`_.slice(array, [start=0], [en | |
<a href="#_slicearray-start0">#</a> [Ⓢ](https://github.com/lodash/lodash/ | d=array.length])` | |
blob/3.0.0/lodash.src.js#L4866 "View in source") [Ⓣ][1] | <a href="#_slicearray-start0-endarraylength">#</a> [Ⓢ](https://github.com | |
/lodash/lodash/blob/4.0.0/lodash.js#L6187 "View in source") [Ⓣ][1] [$ | ||
C3;](https://www.npmjs.com/package/lodash.slice "See the npm package") | ||
Creates a slice of `array` from `start` up to, but not including, `end`. | Creates a slice of `array` from `start` up to, but not including, `end`. | |
*Note:** This function is used instead of `Array#slice` to support node | <br> | |
lists in IE < 9 and to ensure dense arrays are returned. | <br> | |
**Note:** This method is used instead of [`Array#slice`](https://mdn.io/Array/sl | ||
ice) | ||
to ensure dense arrays are returned. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to slice. | 1. `array` *(Array)*: The array to slice. | |
2. `[start=0]` *(number)*: The start position. | 2. `[start=0]` *(number)*: The start position. | |
3. `[end=array.length]` *(number)*: The end position. | 3. `[end=array.length]` *(number)*: The end position. | |
#### Returns | #### Returns | |
*(Array)*: Returns the slice of `array`. | *(Array)*: Returns the slice of `array`. | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_sortedindexarray-value-iteratee_identity-thisarg"></a>`_.sortedIndex | ### <a id="_sortedindexarray-value"></a>`_.sortedIndex(array, value)` | |
(array, value, [iteratee=_.identity], [thisArg])` | <a href="#_sortedindexarray-value">#</a> [Ⓢ](https://github.com/lodash/lo | |
<a href="#_sortedindexarray-value-iteratee_identity-thisarg">#</a> [Ⓢ](ht | dash/blob/4.0.0/lodash.js#L6221 "View in source") [Ⓣ][1] [Ⓝ](https | |
tps://github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L4923 "View in source") | ://www.npmjs.com/package/lodash.sortedindex "See the npm package") | |
[Ⓣ][1] | ||
Uses a binary search to determine the lowest index at which `value` should | Uses a binary search to determine the lowest index at which `value` should | |
be inserted into `array` in order to maintain its sort order. If an iteratee | be inserted into `array` in order to maintain its sort order. | |
function is provided it is invoked for `value` and each element of `array` | ||
to compute their sort ranking. The iteratee is bound to `thisArg` and | ||
invoked with one argument; (value). | ||
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The sorted array to inspect. | 1. `array` *(Array)*: The sorted array to inspect. | |
2. `value` *(*)*: The value to evaluate. | 2. `value` *(*)*: The value to evaluate. | |
3. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per | ||
iteration. If a property name or object is provided it is used to create a "_.pr | ||
operty" or "_.matches" style callback respectively. | ||
4. `[thisArg]` *(*)*: The `this` binding of `iteratee`. | ||
#### Returns | #### Returns | |
*(number)*: Returns the index at which `value` should be inserted | *(number)*: Returns the index at which `value` should be inserted into `array`. | |
into `array`. | ||
#### Example | #### Example | |
```js | ```js | |
_.sortedIndex([30, 50], 40); | _.sortedIndex([30, 50], 40); | |
// => 1 | // => 1 | |
_.sortedIndex([4, 4, 5, 5, 6, 6], 5); | _.sortedIndex([4, 5], 4); | |
// => 2 | // => 0 | |
``` | ||
* * * | ||
<!-- /div --> | ||
var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } }; | <!-- div --> | |
// using an iteratee function | ### <a id="_sortedindexbyarray-value-iteratee_identity"></a>`_.sortedIndexBy(arr | |
_.sortedIndex(['thirty', 'fifty'], 'forty', function(word) { | ay, value, [iteratee=_.identity])` | |
return this.data[word]; | <a href="#_sortedindexbyarray-value-iteratee_identity">#</a> [Ⓢ](https:// | |
}, dict); | github.com/lodash/lodash/blob/4.0.0/lodash.js#L6248 "View in source") [Ⓣ] | |
// => 1 | [1] [Ⓝ](https://www.npmjs.com/package/lodash.sortedindexby "See the npm p | |
ackage") | ||
This method is like `_.sortedIndex` except that it accepts `iteratee` | ||
which is invoked for `value` and each element of `array` to compute their | ||
sort ranking. The iteratee is invoked with one argument: (value). | ||
#### Arguments | ||
1. `array` *(Array)*: The sorted array to inspect. | ||
2. `value` *(*)*: The value to evaluate. | ||
3. `[iteratee=_.identity]` *(Function|Object|string)*: The iteratee invoked per | ||
element. | ||
#### Returns | ||
*(number)*: Returns the index at which `value` should be inserted into `array`. | ||
#### Example | ||
```js | ||
var dict = { 'thirty': 30, 'forty': 40, 'fifty': 50 }; | ||
// using the "_.property" callback shorthand | _.sortedIndexBy(['thirty', 'fifty'], 'forty', _.propertyOf(dict)); | |
_.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x'); | ||
// => 1 | // => 1 | |
// using the `_.property` iteratee shorthand | ||
_.sortedIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x'); | ||
// => 0 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_sortedindexofarray-value"></a>`_.sortedIndexOf(array, value)` | ||
<a href="#_sortedindexofarray-value">#</a> [Ⓢ](https://github.com/lodash/ | ||
lodash/blob/4.0.0/lodash.js#L6267 "View in source") [Ⓣ][1] [Ⓝ](htt | ||
ps://www.npmjs.com/package/lodash.sortedindexof "See the npm package") | ||
This method is like `_.indexOf` except that it performs a binary | ||
search on a sorted `array`. | ||
#### Arguments | ||
1. `array` *(Array)*: The array to search. | ||
2. `value` *(*)*: The value to search for. | ||
#### Returns | ||
*(number)*: Returns the index of the matched value, else `-1`. | ||
#### Example | ||
```js | ||
_.sortedIndexOf([1, 1, 2, 2], 2); | ||
// => 2 | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_sortedlastindexarray-value-iteratee_identity-thisarg"></a>`_.sortedL | ### <a id="_sortedlastindexarray-value"></a>`_.sortedLastIndex(array, value)` | |
astIndex(array, value, [iteratee=_.identity], [thisArg])` | <a href="#_sortedlastindexarray-value">#</a> [Ⓢ](https://github.com/lodas | |
<a href="#_sortedlastindexarray-value-iteratee_identity-thisarg">#</a> [Ⓢ | h/lodash/blob/4.0.0/lodash.js#L6294 "View in source") [Ⓣ][1] [Ⓝ](h | |
](https://github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L4951 "View in sourc | ttps://www.npmjs.com/package/lodash.sortedlastindex "See the npm package") | |
e") [Ⓣ][1] | ||
This method is like `_.sortedIndex` except that it returns the highest | This method is like `_.sortedIndex` except that it returns the highest | |
index at which `value` should be inserted into `array` in order to | index at which `value` should be inserted into `array` in order to | |
maintain its sort order. | maintain its sort order. | |
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The sorted array to inspect. | 1. `array` *(Array)*: The sorted array to inspect. | |
2. `value` *(*)*: The value to evaluate. | 2. `value` *(*)*: The value to evaluate. | |
3. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per | ||
iteration. If a property name or object is provided it is used to create a "_.pr | ||
operty" or "_.matches" style callback respectively. | ||
4. `[thisArg]` *(*)*: The `this` binding of `iteratee`. | ||
#### Returns | #### Returns | |
*(number)*: Returns the index at which `value` should be inserted | *(number)*: Returns the index at which `value` should be inserted into `array`. | |
into `array`. | ||
#### Example | #### Example | |
```js | ```js | |
_.sortedLastIndex([4, 4, 5, 5, 6, 6], 5); | _.sortedLastIndex([4, 5], 4); | |
// => 4 | // => 1 | |
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_sortedlastindexbyarray-value-iteratee_identity"></a>`_.sortedLastInd | ||
exBy(array, value, [iteratee=_.identity])` | ||
<a href="#_sortedlastindexbyarray-value-iteratee_identity">#</a> [Ⓢ](http | ||
s://github.com/lodash/lodash/blob/4.0.0/lodash.js#L6316 "View in source") [$ | ||
C9;][1] [Ⓝ](https://www.npmjs.com/package/lodash.sortedlastindexby "See t | ||
he npm package") | ||
This method is like `_.sortedLastIndex` except that it accepts `iteratee` | ||
which is invoked for `value` and each element of `array` to compute their | ||
sort ranking. The iteratee is invoked with one argument: (value). | ||
#### Arguments | ||
1. `array` *(Array)*: The sorted array to inspect. | ||
2. `value` *(*)*: The value to evaluate. | ||
3. `[iteratee=_.identity]` *(Function|Object|string)*: The iteratee invoked per | ||
element. | ||
#### Returns | ||
*(number)*: Returns the index at which `value` should be inserted into `array`. | ||
#### Example | ||
```js | ||
// using the `_.property` iteratee shorthand | ||
_.sortedLastIndexBy([{ 'x': 4 }, { 'x': 5 }], { 'x': 4 }, 'x'); | ||
// => 1 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_sortedlastindexofarray-value"></a>`_.sortedLastIndexOf(array, value) | ||
` | ||
<a href="#_sortedlastindexofarray-value">#</a> [Ⓢ](https://github.com/lod | ||
ash/lodash/blob/4.0.0/lodash.js#L6335 "View in source") [Ⓣ][1] [Ⓝ] | ||
(https://www.npmjs.com/package/lodash.sortedlastindexof "See the npm package") | ||
This method is like `_.lastIndexOf` except that it performs a binary | ||
search on a sorted `array`. | ||
#### Arguments | ||
1. `array` *(Array)*: The array to search. | ||
2. `value` *(*)*: The value to search for. | ||
#### Returns | ||
*(number)*: Returns the index of the matched value, else `-1`. | ||
#### Example | ||
```js | ||
_.sortedLastIndexOf([1, 1, 2, 2], 2); | ||
// => 3 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_sorteduniqarray"></a>`_.sortedUniq(array)` | ||
<a href="#_sorteduniqarray">#</a> [Ⓢ](https://github.com/lodash/lodash/bl | ||
ob/4.0.0/lodash.js#L6360 "View in source") [Ⓣ][1] [Ⓝ](https://www. | ||
npmjs.com/package/lodash.sorteduniq "See the npm package") | ||
This method is like `_.uniq` except that it's designed and optimized | ||
for sorted arrays. | ||
#### Arguments | ||
1. `array` *(Array)*: The array to inspect. | ||
#### Returns | ||
*(Array)*: Returns the new duplicate free array. | ||
#### Example | ||
```js | ||
_.sortedUniq([1, 1, 2]); | ||
// => [1, 2] | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_sorteduniqbyarray-iteratee"></a>`_.sortedUniqBy(array, [iteratee])` | ||
<a href="#_sorteduniqbyarray-iteratee">#</a> [Ⓢ](https://github.com/lodas | ||
h/lodash/blob/4.0.0/lodash.js#L6381 "View in source") [Ⓣ][1] [Ⓝ](h | ||
ttps://www.npmjs.com/package/lodash.sorteduniqby "See the npm package") | ||
This method is like `_.uniqBy` except that it's designed and optimized | ||
for sorted arrays. | ||
#### Arguments | ||
1. `array` *(Array)*: The array to inspect. | ||
2. `[iteratee]` *(Function)*: The iteratee invoked per element. | ||
#### Returns | ||
*(Array)*: Returns the new duplicate free array. | ||
#### Example | ||
```js | ||
_.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor); | ||
// => [1.1, 2.2] | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_tailarray"></a>`_.tail(array)` | ||
<a href="#_tailarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4.0 | ||
.0/lodash.js#L6400 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs. | ||
com/package/lodash.tail "See the npm package") | ||
Gets all but the first element of `array`. | ||
#### Arguments | ||
1. `array` *(Array)*: The array to query. | ||
#### Returns | ||
*(Array)*: Returns the slice of `array`. | ||
#### Example | ||
```js | ||
_.tail([1, 2, 3]); | ||
// => [2, 3] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_takearray-n1"></a>`_.take(array, [n=1])` | ### <a id="_takearray-n1"></a>`_.take(array, [n=1])` | |
<a href="#_takearray-n1">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 3.0.0/lodash.src.js#L4983 "View in source") [Ⓣ][1] | <a href="#_takearray-n1">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 4.0.0/lodash.js#L6428 "View in source") [Ⓣ][1] [Ⓝ](https://www.npm js.com/package/lodash.take "See the npm package") | |
Creates a slice of `array` with `n` elements taken from the beginning. | Creates a slice of `array` with `n` elements taken from the beginning. | |
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to query. | 1. `array` *(Array)*: The array to query. | |
2. `[n=1]` *(number)*: The number of elements to take. | 2. `[n=1]` *(number)*: The number of elements to take. | |
#### Returns | #### Returns | |
*(Array)*: Returns the slice of `array`. | *(Array)*: Returns the slice of `array`. | |
skipping to change at line 1113 | skipping to change at line 1605 | |
_.take([1, 2, 3], 0); | _.take([1, 2, 3], 0); | |
// => [] | // => [] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_takerightarray-n1"></a>`_.takeRight(array, [n=1])` | ### <a id="_takerightarray-n1"></a>`_.takeRight(array, [n=1])` | |
<a href="#_takerightarray-n1">#</a> [Ⓢ](https://github.com/lodash/lodash/ blob/3.0.0/lodash.src.js#L5019 "View in source") [Ⓣ][1] | <a href="#_takerightarray-n1">#</a> [Ⓢ](https://github.com/lodash/lodash/ blob/4.0.0/lodash.js#L6460 "View in source") [Ⓣ][1] [Ⓝ](https://ww w.npmjs.com/package/lodash.takeright "See the npm package") | |
Creates a slice of `array` with `n` elements taken from the end. | Creates a slice of `array` with `n` elements taken from the end. | |
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to query. | 1. `array` *(Array)*: The array to query. | |
2. `[n=1]` *(number)*: The number of elements to take. | 2. `[n=1]` *(number)*: The number of elements to take. | |
#### Returns | #### Returns | |
*(Array)*: Returns the slice of `array`. | *(Array)*: Returns the slice of `array`. | |
skipping to change at line 1144 | skipping to change at line 1636 | |
_.takeRight([1, 2, 3], 0); | _.takeRight([1, 2, 3], 0); | |
// => [] | // => [] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_takerightwhilearray-predicate_identity-thisarg"></a>`_.takeRightWhil | ### <a id="_takerightwhilearray-predicate_identity"></a>`_.takeRightWhile(array, | |
e(array, [predicate=_.identity], [thisArg])` | [predicate=_.identity])` | |
<a href="#_takerightwhilearray-predicate_identity-thisarg">#</a> [Ⓢ](http | <a href="#_takerightwhilearray-predicate_identity">#</a> [Ⓢ](https://gith | |
s://github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L5071 "View in source") [& | ub.com/lodash/lodash/blob/4.0.0/lodash.js#L6504 "View in source") [Ⓣ][1] | |
#x24C9;][1] | [Ⓝ](https://www.npmjs.com/package/lodash.takerightwhile "See the npm pack | |
age") | ||
Creates a slice of `array` with elements taken from the end. Elements are | Creates a slice of `array` with elements taken from the end. Elements are | |
taken until `predicate` returns falsey. The predicate is bound to `thisArg` | taken until `predicate` returns falsey. The predicate is invoked with three | |
and invoked with three arguments; (value, index, array). | arguments: (value, index, array). | |
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to query. | 1. `array` *(Array)*: The array to query. | |
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | |
element. | iteration. | |
3. `[thisArg]` *(*)*: The `this` binding of `predicate`. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the slice of `array`. | *(Array)*: Returns the slice of `array`. | |
#### Example | #### Example | |
```js | ```js | |
_.takeRightWhile([1, 2, 3], function(n) { return n > 1; }); | ||
// => [2, 3] | ||
var users = [ | var users = [ | |
{ 'user': 'barney', 'status': 'busy', 'active': false }, | { 'user': 'barney', 'active': true }, | |
{ 'user': 'fred', 'status': 'busy', 'active': true }, | { 'user': 'fred', 'active': false }, | |
{ 'user': 'pebbles', 'status': 'away', 'active': true } | { 'user': 'pebbles', 'active': false } | |
]; | ]; | |
// using the "_.property" callback shorthand | _.takeRightWhile(users, function(o) { return !o.active; }); | |
_.pluck(_.takeRightWhile(users, 'active'), 'user'); | // => objects for ['fred', 'pebbles'] | |
// => ['fred', 'pebbles'] | ||
// using the `_.matches` iteratee shorthand | ||
_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }); | ||
// => objects for ['pebbles'] | ||
// using the `_.matchesProperty` iteratee shorthand | ||
_.takeRightWhile(users, ['active', false]); | ||
// => objects for ['fred', 'pebbles'] | ||
// using the "_.matches" callback shorthand | // using the `_.property` iteratee shorthand | |
_.pluck(_.takeRightWhile(users, { 'status': 'away' }), 'user'); | _.takeRightWhile(users, 'active'); | |
// => ['pebbles'] | // => [] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_takewhilearray-predicate_identity-thisarg"></a>`_.takeWhile(array, [ | ### <a id="_takewhilearray-predicate_identity"></a>`_.takeWhile(array, [predicat | |
predicate=_.identity], [thisArg])` | e=_.identity])` | |
<a href="#_takewhilearray-predicate_identity-thisarg">#</a> [Ⓢ](https://g | <a href="#_takewhilearray-predicate_identity">#</a> [Ⓢ](https://github.co | |
ithub.com/lodash/lodash/blob/3.0.0/lodash.src.js#L5121 "View in source") [Ɍ | m/lodash/lodash/blob/4.0.0/lodash.js#L6544 "View in source") [Ⓣ][1] [ | |
9;][1] | 4C3;](https://www.npmjs.com/package/lodash.takewhile "See the npm package") | |
Creates a slice of `array` with elements taken from the beginning. Elements | Creates a slice of `array` with elements taken from the beginning. Elements | |
are taken until `predicate` returns falsey. The predicate is bound to | are taken until `predicate` returns falsey. The predicate is invoked with | |
`thisArg` and invoked with three arguments; (value, index, array). | three arguments: (value, index, array). | |
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to query. | 1. `array` *(Array)*: The array to query. | |
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | |
element. | iteration. | |
3. `[thisArg]` *(*)*: The `this` binding of `predicate`. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the slice of `array`. | *(Array)*: Returns the slice of `array`. | |
#### Example | #### Example | |
```js | ```js | |
_.takeWhile([1, 2, 3], function(n) { return n < 3; }); | ||
// => [1, 2] | ||
var users = [ | var users = [ | |
{ 'user': 'barney', 'status': 'busy', 'active': true }, | { 'user': 'barney', 'active': false }, | |
{ 'user': 'fred', 'status': 'busy', 'active': false }, | { 'user': 'fred', 'active': false}, | |
{ 'user': 'pebbles', 'status': 'away', 'active': true } | { 'user': 'pebbles', 'active': true } | |
]; | ]; | |
// using the "_.property" callback shorthand | _.takeWhile(users, function(o) { return !o.active; }); | |
_.pluck(_.takeWhile(users, 'active'), 'user'); | // => objects for ['barney', 'fred'] | |
// => ['barney'] | ||
// using the "_.matches" callback shorthand | // using the `_.matches` iteratee shorthand | |
_.pluck(_.takeWhile(users, { 'status': 'busy' }), 'user'); | _.takeWhile(users, { 'user': 'barney', 'active': false }); | |
// => ['barney', 'fred'] | // => objects for ['barney'] | |
// using the `_.matchesProperty` iteratee shorthand | ||
_.takeWhile(users, ['active', false]); | ||
// => objects for ['barney', 'fred'] | ||
// using the `_.property` iteratee shorthand | ||
_.takeWhile(users, 'active'); | ||
// => [] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_unionarrays"></a>`_.union([arrays])` | ### <a id="_unionarrays"></a>`_.union([arrays])` | |
<a href="#_unionarrays">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3 .0.0/lodash.src.js#L5151 "View in source") [Ⓣ][1] | <a href="#_unionarrays">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4 .0.0/lodash.js#L6565 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmj s.com/package/lodash.union "See the npm package") | |
Creates an array of unique values, in order, of the provided arrays using | Creates an array of unique values, in order, from all of the provided arrays | |
`SameValueZero` for equality comparisons. | using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevalu | |
*Note:** `SameValueZero` comparisons are like strict equality comparisons, | ezero) | |
e.g. `===`, except that `NaN` matches `NaN`. See the | for equality comparisons. | |
[ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezer | ||
o) | ||
for more details. | ||
#### Arguments | #### Arguments | |
1. `[arrays]` *(...Array)*: The arrays to inspect. | 1. `[arrays]` *(...Array)*: The arrays to inspect. | |
#### Returns | #### Returns | |
*(Array)*: Returns the new array of combined values. | *(Array)*: Returns the new array of combined values. | |
#### Example | #### Example | |
```js | ```js | |
_.union([1, 2, 3], [5, 2, 1, 4], [2, 1]); | _.union([2, 1], [4, 2], [1, 2]); | |
// => [1, 2, 3, 5, 4] | // => [2, 1, 4] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_uniqarray-issorted-iteratee-thisarg"></a>`_.uniq(array, [isSorted], | ### <a id="_unionbyarrays-iteratee_identity"></a>`_.unionBy([arrays], [iteratee= | |
[iteratee], [thisArg])` | _.identity])` | |
<a href="#_uniqarray-issorted-iteratee-thisarg">#</a> [Ⓢ](https://github. | <a href="#_unionbyarrays-iteratee_identity">#</a> [Ⓢ](https://github.com/ | |
com/lodash/lodash/blob/3.0.0/lodash.src.js#L5203 "View in source") [Ⓣ][1] | lodash/lodash/blob/4.0.0/lodash.js#L6589 "View in source") [Ⓣ][1] [Ɍ | |
3;](https://www.npmjs.com/package/lodash.unionby "See the npm package") | ||
Creates a duplicate-value-free version of an array using `SameValueZero` | This method is like `_.union` except that it accepts `iteratee` which is | |
for equality comparisons. Providing `true` for `isSorted` performs a faster | invoked for each element of each `arrays` to generate the criterion by which | |
search algorithm for sorted arrays. If an iteratee function is provided it | uniqueness is computed. The iteratee is invoked with one argument: (value). | |
is invoked for each value in the array to generate the criterion by which | ||
uniqueness is computed. The `iteratee` is bound to `thisArg` and invoked | ||
with three arguments; (value, index, array). | ||
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
*Note:** `SameValueZero` comparisons are like strict equality comparisons, | ||
e.g. `===`, except that `NaN` matches `NaN`. See the | ||
[ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezer | ||
o) | ||
for more details. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to inspect. | 1. `[arrays]` *(...Array)*: The arrays to inspect. | |
2. `[isSorted]` *(boolean)*: Specify the array is sorted. | 2. `[iteratee=_.identity]` *(Function|Object|string)*: The iteratee invoked per | |
3. `[iteratee]` *(Function|Object|string)*: The function invoked per iteration. | element. | |
If a property name or object is provided it is used to create a "_.property" or | ||
"_.matches" style callback respectively. | ||
4. `[thisArg]` *(*)*: The `this` binding of `iteratee`. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the new duplicate-value-free array. | *(Array)*: Returns the new array of combined values. | |
#### Example | #### Example | |
```js | ```js | |
_.uniq([1, 2, 1]); | _.unionBy([2.1, 1.2], [4.3, 2.4], Math.floor); | |
// => [1, 2] | // => [2.1, 1.2, 4.3] | |
// using `isSorted` | ||
_.uniq([1, 1, 2], true); | ||
// => [1, 2] | ||
// using an iteratee function | // using the `_.property` iteratee shorthand | |
_.uniq([1, 2.5, 1.5, 2], function(n) { return this.floor(n); }, Math); | _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); | |
// => [1, 2.5] | ||
// using the "_.property" callback shorthand | ||
_.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); | ||
// => [{ 'x': 1 }, { 'x': 2 }] | // => [{ 'x': 1 }, { 'x': 2 }] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_unziparray"></a>`_.unzip(array)` | ### <a id="_unionwitharrays-comparator"></a>`_.unionWith([arrays], [comparator]) | |
<a href="#_unziparray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3. | ` | |
0.0/lodash.src.js#L5241 "View in source") [Ⓣ][1] | <a href="#_unionwitharrays-comparator">#</a> [Ⓢ](https://github.com/lodas | |
h/lodash/blob/4.0.0/lodash.js#L6616 "View in source") [Ⓣ][1] [Ⓝ](h | ||
ttps://www.npmjs.com/package/lodash.unionwith "See the npm package") | ||
This method is like `_.zip` except that it accepts an array of grouped | This method is like `_.union` except that it accepts `comparator` which | |
elements and creates an array regrouping the elements to their pre-`_.zip` | is invoked to compare elements of `arrays`. The comparator is invoked | |
configuration. | with two arguments: (arrVal, othVal). | |
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array of grouped elements to process. | 1. `[arrays]` *(...Array)*: The arrays to inspect. | |
2. `[comparator]` *(Function)*: The comparator invoked per element. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the new array of regrouped elements. | *(Array)*: Returns the new array of combined values. | |
#### Example | #### Example | |
```js | ```js | |
var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]); | var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; | |
// => [['fred', 30, true], ['barney', 40, false]] | var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; | |
_.unzip(zipped); | _.unionWith(objects, others, _.isEqual); | |
// => [['fred', 'barney'], [30, 40], [true, false]] | // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_withoutarray-values"></a>`_.without(array, [values])` | ### <a id="_uniqarray"></a>`_.uniq(array)` | |
<a href="#_withoutarray-values">#</a> [Ⓢ](https://github.com/lodash/lodas | <a href="#_uniqarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4.0 | |
h/blob/3.0.0/lodash.src.js#L5272 "View in source") [Ⓣ][1] | .0/lodash.js#L6640 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs. | |
com/package/lodash.uniq "See the npm package") | ||
Creates an array excluding all provided values using `SameValueZero` for | Creates a duplicate-free version of an array, using | |
equality comparisons. | [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) | |
*Note:** `SameValueZero` comparisons are like strict equality comparisons, | for equality comparisons, in which only the first occurrence of each element | |
e.g. `===`, except that `NaN` matches `NaN`. See the | is kept. | |
[ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezer | ||
o) | ||
for more details. | ||
#### Arguments | #### Arguments | |
1. `array` *(Array)*: The array to filter. | 1. `array` *(Array)*: The array to inspect. | |
2. `[values]` *(...*)*: The values to exclude. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the new array of filtered values. | *(Array)*: Returns the new duplicate free array. | |
#### Example | #### Example | |
```js | ```js | |
_.without([1, 2, 1, 0, 3, 1, 4], 0, 1); | _.uniq([2, 1, 2]); | |
// => [2, 3, 4] | // => [2, 1] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_xorarrays"></a>`_.xor([arrays])` | ### <a id="_uniqbyarray-iteratee_identity"></a>`_.uniqBy(array, [iteratee=_.iden | |
<a href="#_xorarrays">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.0 | tity])` | |
.0/lodash.src.js#L5294 "View in source") [Ⓣ][1] | <a href="#_uniqbyarray-iteratee_identity">#</a> [Ⓢ](https://github.com/lo | |
dash/lodash/blob/4.0.0/lodash.js#L6666 "View in source") [Ⓣ][1] [Ⓝ | ||
](https://www.npmjs.com/package/lodash.uniqby "See the npm package") | ||
Creates an array that is the symmetric difference of the provided arrays. | This method is like `_.uniq` except that it accepts `iteratee` which is | |
See [Wikipedia](https://en.wikipedia.org/wiki/Symmetric_difference) for | invoked for each element in `array` to generate the criterion by which | |
more details. | uniqueness is computed. The iteratee is invoked with one argument: (value). | |
#### Arguments | #### Arguments | |
1. `[arrays]` *(...Array)*: The arrays to inspect. | 1. `array` *(Array)*: The array to inspect. | |
2. `[iteratee=_.identity]` *(Function|Object|string)*: The iteratee invoked per | ||
element. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the new array of values. | *(Array)*: Returns the new duplicate free array. | |
#### Example | #### Example | |
```js | ```js | |
_.xor([1, 2, 3], [5, 2, 1, 4]); | _.uniqBy([2.1, 1.2, 2.3], Math.floor); | |
// => [3, 5, 4] | // => [2.1, 1.2] | |
_.xor([1, 2, 5], [2, 3, 5], [3, 4, 5]); | // using the `_.property` iteratee shorthand | |
// => [1, 4, 5] | _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); | |
// => [{ 'x': 1 }, { 'x': 2 }] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_ziparrays"></a>`_.zip([arrays])` | ### <a id="_uniqwitharray-comparator"></a>`_.uniqWith(array, [comparator])` | |
<a href="#_ziparrays">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.0 | <a href="#_uniqwitharray-comparator">#</a> [Ⓢ](https://github.com/lodash/ | |
.0/lodash.src.js#L5324 "View in source") [Ⓣ][1] | lodash/blob/4.0.0/lodash.js#L6690 "View in source") [Ⓣ][1] [Ⓝ](htt | |
ps://www.npmjs.com/package/lodash.uniqwith "See the npm package") | ||
Creates an array of grouped elements, the first of which contains the first | This method is like `_.uniq` except that it accepts `comparator` which | |
elements of the given arrays, the second of which contains the second elements | is invoked to compare elements of `array`. The comparator is invoked with | |
of the given arrays, and so on. | two arguments: (arrVal, othVal). | |
#### Arguments | #### Arguments | |
1. `[arrays]` *(...Array)*: The arrays to process. | 1. `array` *(Array)*: The array to inspect. | |
2. `[comparator]` *(Function)*: The comparator invoked per element. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the new array of grouped elements. | *(Array)*: Returns the new duplicate free array. | |
#### Example | #### Example | |
```js | ```js | |
_.zip(['fred', 'barney'], [30, 40], [true, false]); | var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }]; | |
// => [['fred', 30, true], ['barney', 40, false]] | ||
_.uniqWith(objects, _.isEqual); | ||
// => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_zipobjectprops-values"></a>`_.zipObject(props, [values=[]])` | ### <a id="_unziparray"></a>`_.unzip(array)` | |
<a href="#_zipobjectprops-values">#</a> [Ⓢ](https://github.com/lodash/lod | <a href="#_unziparray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4. | |
ash/blob/3.0.0/lodash.src.js#L5351 "View in source") [Ⓣ][1] | 0.0/lodash.js#L6714 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs | |
.com/package/lodash.unzip "See the npm package") | ||
Creates an object composed from arrays of property names and values. Provide | This method is like `_.zip` except that it accepts an array of grouped | |
either a single two dimensional array, e.g. `[[key1, value1], [key2, value2]]` | elements and creates an array regrouping the elements to their pre-zip | |
or two arrays, one of property names and one of corresponding values. | configuration. | |
#### Arguments | #### Arguments | |
1. `props` *(Array)*: The property names. | 1. `array` *(Array)*: The array of grouped elements to process. | |
2. `[values=[]]` *(Array)*: The property values. | ||
#### Returns | #### Returns | |
*(Object)*: Returns the new object. | *(Array)*: Returns the new array of regrouped elements. | |
#### Example | #### Example | |
```js | ```js | |
_.zipObject(['fred', 'barney'], [30, 40]); | var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]); | |
// => { 'fred': 30, 'barney': 40 } | // => [['fred', 30, true], ['barney', 40, false]] | |
_.unzip(zipped); | ||
// => [['fred', 'barney'], [30, 40], [true, false]] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- /div --> | ||
<!-- div --> | ||
## `“Chain” Methods` | ||
<!-- div --> | <!-- div --> | |
### <a id="_value"></a>`._(value)` | ### <a id="_unzipwitharray-iteratee_identity"></a>`_.unzipWith(array, [iteratee= | |
<a href="#_value">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.0.0/l | _.identity])` | |
odash.src.js#L919 "View in source") [Ⓣ][1] | <a href="#_unzipwitharray-iteratee_identity">#</a> [Ⓢ](https://github.com | |
/lodash/lodash/blob/4.0.0/lodash.js#L6749 "View in source") [Ⓣ][1] [$ | ||
Creates a `lodash` object which wraps `value` to enable intuitive chaining. | C3;](https://www.npmjs.com/package/lodash.unzipwith "See the npm package") | |
Methods that operate on and return arrays, collections, and functions can | ||
be chained together. Methods that return a boolean or single value will | ||
automatically end the chain returning the unwrapped value. Explicit chaining | ||
may be enabled using `_.chain`. The execution of chained methods is lazy, | ||
that is, execution is deferred until `_#value` is implicitly or explicitly | ||
called. | ||
Lazy evaluation allows several methods to support shortcut fusion. Shortcut | ||
fusion is an optimization that merges iteratees to avoid creating intermediate | ||
arrays and reduce the number of iteratee executions. | ||
Chaining is supported in custom builds as long as the `_#value` method is | ||
directly or indirectly included in the build. | ||
In addition to lodash methods, wrappers also have the following `Array` methods: | ||
`concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`, | ||
and `unshift` | ||
The wrapper functions that support shortcut fusion are: | ||
`drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `first`, | ||
`initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`, `slice`, | ||
`take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `where` | ||
The chainable wrapper functions are: | ||
`after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`, | ||
`callback`, `chain`, `chunk`, `compact`, `concat`, `constant`, `countBy`, | ||
`create`, `curry`, `debounce`, `defaults`, `defer`, `delay`, `difference`, | ||
`drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`, `flatten`, | ||
`flattenDeep`, `flow`, `flowRight`, `forEach`, `forEachRight`, `forIn`, | ||
`forInRight`, `forOwn`, `forOwnRight`, `functions`, `groupBy`, `indexBy`, | ||
`initial`, `intersection`, `invert`, `invoke`, `keys`, `keysIn`, `map`, | ||
`mapValues`, `matches`, `memoize`, `merge`, `mixin`, `negate`, `noop`, | ||
`omit`, `once`, `pairs`, `partial`, `partialRight`, `partition`, `pick`, | ||
`pluck`, `property`, `propertyOf`, `pull`, `pullAt`, `push`, `range`, | ||
`rearg`, `reject`, `remove`, `rest`, `reverse`, `shuffle`, `slice`, `sort`, | ||
`sortBy`, `sortByAll`, `splice`, `take`, `takeRight`, `takeRightWhile`, | ||
`takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`, | ||
`transform`, `union`, `uniq`, `unshift`, `unzip`, `values`, `valuesIn`, | ||
`where`, `without`, `wrap`, `xor`, `zip`, and `zipObject` | ||
The wrapper functions that are **not** chainable by default are: | ||
`attempt`, `camelCase`, `capitalize`, `clone`, `cloneDeep`, `deburr`, | ||
`endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, | ||
`findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`, `has`, | ||
`identity`, `includes`, `indexOf`, `isArguments`, `isArray`, `isBoolean`, | ||
`isDate`, `isElement`, `isEmpty`, `isEqual`, `isError`, `isFinite`, | ||
`isFunction`, `isMatch` , `isNative`, `isNaN`, `isNull`, `isNumber`, | ||
`isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, | ||
`isTypedArray`, `join`, `kebabCase`, `last`, `lastIndexOf`, `max`, `min`, | ||
`noConflict`, `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, | ||
`random`, `reduce`, `reduceRight`, `repeat`, `result`, `runInContext`, | ||
`shift`, `size`, `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, | ||
`startsWith`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`, | ||
`unescape`, `uniqueId`, `value`, and `words` | ||
The wrapper function `sample` will return a wrapped value when `n` is provided, | This method is like `_.unzip` except that it accepts `iteratee` to specify | |
otherwise an unwrapped value is returned. | how regrouped values should be combined. The iteratee is invoked with the | |
elements of each group: (...group). | ||
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to wrap in a `lodash` instance. | 1. `array` *(Array)*: The array of grouped elements to process. | |
2. `[iteratee=_.identity]` *(Function)*: The function to combine regrouped value | ||
s. | ||
#### Returns | #### Returns | |
*(Object)*: Returns a `lodash` instance. | *(Array)*: Returns the new array of regrouped elements. | |
#### Example | #### Example | |
```js | ```js | |
var wrapped = _([1, 2, 3]); | var zipped = _.zip([1, 2], [10, 20], [100, 200]); | |
// => [[1, 10, 100], [2, 20, 200]] | ||
// returns an unwrapped value | ||
wrapped.reduce(function(sum, n) { return sum + n; }); | ||
// => 6 | ||
// returns a wrapped value | ||
var squares = wrapped.map(function(n) { return n * n; }); | ||
_.isArray(squares); | ||
// => false | ||
_.isArray(squares.value()); | _.unzipWith(zipped, _.add); | |
// => true | // => [3, 30, 300] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_chainvalue"></a>`_.chain(value)` | ### <a id="_withoutarray-values"></a>`_.without(array, [values])` | |
<a href="#_chainvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3. | <a href="#_withoutarray-values">#</a> [Ⓢ](https://github.com/lodash/lodas | |
0.0/lodash.src.js#L5396 "View in source") [Ⓣ][1] | h/blob/4.0.0/lodash.js#L6778 "View in source") [Ⓣ][1] [Ⓝ](https:// | |
www.npmjs.com/package/lodash.without "See the npm package") | ||
Creates a `lodash` object that wraps `value` with explicit method | Creates an array excluding all provided values using | |
chaining enabled. | [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) | |
for equality comparisons. | ||
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to wrap. | 1. `array` *(Array)*: The array to filter. | |
2. `[values]` *(...*)*: The values to exclude. | ||
#### Returns | #### Returns | |
*(Object)*: Returns the new `lodash` object. | *(Array)*: Returns the new array of filtered values. | |
#### Example | #### Example | |
```js | ```js | |
var users = [ | _.without([1, 2, 1, 3], 1, 2); | |
{ 'user': 'barney', 'age': 36 }, | // => [3] | |
{ 'user': 'fred', 'age': 40 }, | ||
{ 'user': 'pebbles', 'age': 1 } | ||
]; | ||
var youngest = _.chain(users) | ||
.sortBy('age') | ||
.map(function(chr) { return chr.user + ' is ' + chr.age; }) | ||
.first() | ||
.value(); | ||
// => 'pebbles is 1' | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_tapvalue-interceptor-thisarg"></a>`_.tap(value, interceptor, [thisAr | ### <a id="_xorarrays"></a>`_.xor([arrays])` | |
g])` | <a href="#_xorarrays">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4.0 | |
<a href="#_tapvalue-interceptor-thisarg">#</a> [Ⓢ](https://github.com/lod | .0/lodash.js#L6798 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs. | |
ash/lodash/blob/3.0.0/lodash.src.js#L5423 "View in source") [Ⓣ][1] | com/package/lodash.xor "See the npm package") | |
This method invokes `interceptor` and returns `value`. The interceptor is | Creates an array of unique values that is the [symmetric difference](https://en. | |
bound to `thisArg` and invoked with one argument; (value). The purpose of | wikipedia.org/wiki/Symmetric_difference) | |
this method is to "tap into" a method chain in order to perform operations | of the provided arrays. | |
on intermediate results within the chain. | ||
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to provide to `interceptor`. | 1. `[arrays]` *(...Array)*: The arrays to inspect. | |
2. `interceptor` *(Function)*: The function to invoke. | ||
3. `[thisArg]` *(*)*: The `this` binding of `interceptor`. | ||
#### Returns | #### Returns | |
*(*)*: Returns `value`. | *(Array)*: Returns the new array of values. | |
#### Example | #### Example | |
```js | ```js | |
_([1, 2, 3]) | _.xor([2, 1], [4, 2]); | |
.tap(function(array) { array.pop(); }) | // => [1, 4] | |
.reverse() | ||
.value(); | ||
// => [2, 1] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_thruvalue-interceptor-thisarg"></a>`_.thru(value, interceptor, [this | ### <a id="_xorbyarrays-iteratee_identity"></a>`_.xorBy([arrays], [iteratee=_.id | |
Arg])` | entity])` | |
<a href="#_thruvalue-interceptor-thisarg">#</a> [Ⓢ](https://github.com/lo | <a href="#_xorbyarrays-iteratee_identity">#</a> [Ⓢ](https://github.com/lo | |
dash/lodash/blob/3.0.0/lodash.src.js#L5446 "View in source") [Ⓣ][1] | dash/lodash/blob/4.0.0/lodash.js#L6822 "View in source") [Ⓣ][1] [Ⓝ | |
](https://www.npmjs.com/package/lodash.xorby "See the npm package") | ||
This method is like `_.tap` except that it returns the result of `interceptor`. | This method is like `_.xor` except that it accepts `iteratee` which is | |
invoked for each element of each `arrays` to generate the criterion by which | ||
uniqueness is computed. The iteratee is invoked with one argument: (value). | ||
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to provide to `interceptor`. | 1. `[arrays]` *(...Array)*: The arrays to inspect. | |
2. `interceptor` *(Function)*: The function to invoke. | 2. `[iteratee=_.identity]` *(Function|Object|string)*: The iteratee invoked per | |
3. `[thisArg]` *(*)*: The `this` binding of `interceptor`. | element. | |
#### Returns | #### Returns | |
*(*)*: Returns the result of `interceptor`. | *(Array)*: Returns the new array of values. | |
#### Example | #### Example | |
```js | ```js | |
_([1, 2, 3]) | _.xorBy([2.1, 1.2], [4.3, 2.4], Math.floor); | |
.last() | // => [1.2, 4.3] | |
.thru(function(value) { return [value]; }) | ||
.value(); | // using the `_.property` iteratee shorthand | |
// => [3] | _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); | |
// => [{ 'x': 2 }] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_prototypechain"></a>`_.prototype.chain()` | ### <a id="_xorwitharrays-comparator"></a>`_.xorWith([arrays], [comparator])` | |
<a href="#_prototypechain">#</a> [Ⓢ](https://github.com/lodash/lodash/blo | <a href="#_xorwitharrays-comparator">#</a> [Ⓢ](https://github.com/lodash/ | |
b/3.0.0/lodash.src.js#L5475 "View in source") [Ⓣ][1] | lodash/blob/4.0.0/lodash.js#L6849 "View in source") [Ⓣ][1] [Ⓝ](htt | |
ps://www.npmjs.com/package/lodash.xorwith "See the npm package") | ||
Enables explicit method chaining on the wrapper object. | This method is like `_.xor` except that it accepts `comparator` which is | |
invoked to compare elements of `arrays`. The comparator is invoked with | ||
two arguments: (arrVal, othVal). | ||
#### Arguments | ||
1. `[arrays]` *(...Array)*: The arrays to inspect. | ||
2. `[comparator]` *(Function)*: The comparator invoked per element. | ||
#### Returns | #### Returns | |
*(*)*: Returns the `lodash` object. | *(Array)*: Returns the new array of values. | |
#### Example | #### Example | |
```js | ```js | |
var users = [ | var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; | |
{ 'user': 'barney', 'age': 36 }, | var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; | |
{ 'user': 'fred', 'age': 40 } | ||
]; | ||
// without explicit chaining | _.xorWith(objects, others, _.isEqual); | |
_(users).first(); | // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] | |
// => { 'user': 'barney', 'age': 36 } | ||
// with explicit chaining | ||
_(users).chain() | ||
.first() | ||
.pick('user') | ||
.value(); | ||
// => { 'user': 'barney' } | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_prototypereverse"></a>`_.prototype.reverse()` | ### <a id="_ziparrays"></a>`_.zip([arrays])` | |
<a href="#_prototypereverse">#</a> [Ⓢ](https://github.com/lodash/lodash/b | <a href="#_ziparrays">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4.0 | |
lob/3.0.0/lodash.src.js#L5499 "View in source") [Ⓣ][1] | .0/lodash.js#L6872 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs. | |
com/package/lodash.zip "See the npm package") | ||
Reverses the wrapped array so the first element becomes the last, the | Creates an array of grouped elements, the first of which contains the first | |
second element becomes the second to last, and so on. | elements of the given arrays, the second of which contains the second elements | |
*Note:** This method mutates the wrapped array. | of the given arrays, and so on. | |
#### Arguments | ||
1. `[arrays]` *(...Array)*: The arrays to process. | ||
#### Returns | #### Returns | |
*(Object)*: Returns the new reversed `lodash` object. | *(Array)*: Returns the new array of grouped elements. | |
#### Example | #### Example | |
```js | ```js | |
var array = [1, 2, 3]; | _.zip(['fred', 'barney'], [30, 40], [true, false]); | |
// => [['fred', 30, true], ['barney', 40, false]] | ||
_(array).reverse().value() | ||
// => [3, 2, 1] | ||
console.log(array); | ||
// => [3, 2, 1] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_prototypetostring"></a>`_.prototype.toString()` | ### <a id="_zipobjectprops-values"></a>`_.zipObject([props=[]], [values=[]])` | |
<a href="#_prototypetostring">#</a> [Ⓢ](https://github.com/lodash/lodash/ | <a href="#_zipobjectprops-values">#</a> [Ⓢ](https://github.com/lodash/lod | |
blob/3.0.0/lodash.src.js#L5521 "View in source") [Ⓣ][1] | ash/blob/4.0.0/lodash.js#L6889 "View in source") [Ⓣ][1] [Ⓝ](https: | |
//www.npmjs.com/package/lodash.zipobject "See the npm package") | ||
Produces the result of coercing the unwrapped value to a string. | This method is like `_.fromPairs` except that it accepts two arrays, | |
one of property names and one of corresponding values. | ||
#### Arguments | ||
1. `[props=[]]` *(Array)*: The property names. | ||
2. `[values=[]]` *(Array)*: The property values. | ||
#### Returns | #### Returns | |
*(string)*: Returns the coerced string value. | *(Object)*: Returns the new object. | |
#### Example | #### Example | |
```js | ```js | |
_([1, 2, 3]).toString(); | _.zipObject(['fred', 'barney'], [30, 40]); | |
// => '1,2,3' | // => { 'fred': 30, 'barney': 40 } | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_prototypevalue"></a>`_.prototype.value()` | ### <a id="_zipwitharrays-iteratee_identity"></a>`_.zipWith([arrays], [iteratee= | |
<a href="#_prototypevalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blo | _.identity])` | |
b/3.0.0/lodash.src.js#L5538 "View in source") [Ⓣ][1] | <a href="#_zipwitharrays-iteratee_identity">#</a> [Ⓢ](https://github.com/ | |
lodash/lodash/blob/4.0.0/lodash.js#L6919 "View in source") [Ⓣ][1] [Ɍ | ||
3;](https://www.npmjs.com/package/lodash.zipwith "See the npm package") | ||
Executes the chained sequence to extract the unwrapped value. | This method is like `_.zip` except that it accepts `iteratee` to specify | |
how grouped values should be combined. The iteratee is invoked with the | ||
elements of each group: (...group). | ||
#### Arguments | ||
1. `[arrays]` *(...Array)*: The arrays to process. | ||
2. `[iteratee=_.identity]` *(Function)*: The function to combine grouped values. | ||
#### Returns | #### Returns | |
*(*)*: Returns the resolved unwrapped value. | *(Array)*: Returns the new array of grouped elements. | |
#### Example | #### Example | |
```js | ```js | |
_([1, 2, 3]).value(); | _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) { | |
// => [1, 2, 3] | return a + b + c; | |
}); | ||
// => [111, 222] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- /div --> | ||
<!-- div --> | <!-- div --> | |
## `“Collection” Methods` | ### <a id="_prototypereverse"></a>`_.prototype.reverse()` | |
<a href="#_prototypereverse">#</a> [Ⓢ](https://github.com/lodash/lodash/b | ||
<!-- div --> | lob/4.0.0/lodash.js#L6169 "View in source") [Ⓣ][1] [Ⓝ](https://www | |
.npmjs.com/package/lodash.reverse "See the npm package") | ||
### <a id="_atcollection-props"></a>`_.at(collection, [props])` | ||
<a href="#_atcollection-props">#</a> [Ⓢ](https://github.com/lodash/lodash | ||
/blob/3.0.0/lodash.src.js#L5564 "View in source") [Ⓣ][1] | ||
Creates an array of elements corresponding to the given keys, or indexes, | Reverses `array` so that the first element becomes the last, the second | |
of `collection`. Keys may be specified as individual arguments or as arrays | element becomes the second to last, and so on. | |
of keys. | <br> | |
<br> | ||
#### Arguments | **Note:** This method mutates `array` and is based on | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | [`Array#reverse`](https://mdn.io/Array/reverse). | |
2. `[props]` *(...(number|number[]|string|string[])*: The proper | ||
ty names or indexes of elements to pick, specified individually or in arrays. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the new array of picked elements. | *(Array)*: Returns `array`. | |
#### Example | #### Example | |
```js | ```js | |
_.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]); | var array = [1, 2, 3]; | |
// => ['a', 'c', 'e'] | ||
_.reverse(array); | ||
// => [3, 2, 1] | ||
_.at(['fred', 'barney', 'pebbles'], 0, 2); | console.log(array); | |
// => ['fred', 'pebbles'] | // => [3, 2, 1] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- /div --> | ||
<!-- div --> | ||
## `“Collection” Methods` | ||
<!-- div --> | <!-- div --> | |
### <a id="_countbycollection-iteratee_identity-thisarg"></a>`_.countBy(collecti | ### <a id="_countbycollection-iteratee_identity"></a>`_.countBy(collection, [ite | |
on, [iteratee=_.identity], [thisArg])` | ratee=_.identity])` | |
<a href="#_countbycollection-iteratee_identity-thisarg">#</a> [Ⓢ](https:/ | <a href="#_countbycollection-iteratee_identity">#</a> [Ⓢ](https://github. | |
/github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L5657 "View in source") [ | com/lodash/lodash/blob/4.0.0/lodash.js#L7299 "View in source") [Ⓣ][1] [&# | |
4C9;][1] | x24C3;](https://www.npmjs.com/package/lodash.countby "See the npm package") | |
Creates an object composed of keys generated from the results of running | Creates an object composed of keys generated from the results of running | |
each element of `collection` through `iteratee`. The corresponding value | each element of `collection` through `iteratee`. The corresponding value | |
of each key is the number of times the key was returned by `iteratee`. | of each key is the number of times the key was returned by `iteratee`. | |
The `iteratee` is bound to `thisArg` and invoked with three arguments; | The iteratee is invoked with one argument: (value). | |
(value, index|key, collection). | ||
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | 1. `collection` *(Array|Object)*: The collection to iterate over. | |
2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `[iteratee=_.identity]` *(Function|Object|string)*: The iteratee invoked per | |
iteration. If a property name or object is provided it is used to create a "_.pr | element. | |
operty" or "_.matches" style callback respectively. | ||
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. | ||
#### Returns | #### Returns | |
*(Object)*: Returns the composed aggregate object. | *(Object)*: Returns the composed aggregate object. | |
#### Example | #### Example | |
```js | ```js | |
_.countBy([4.3, 6.1, 6.4], function(n) { return Math.floor(n); }); | _.countBy([6.1, 4.2, 6.3], Math.floor); | |
// => { '4': 1, '6': 2 } | ||
_.countBy([4.3, 6.1, 6.4], function(n) { return this.floor(n); }, Math); | ||
// => { '4': 1, '6': 2 } | // => { '4': 1, '6': 2 } | |
_.countBy(['one', 'two', 'three'], 'length'); | _.countBy(['one', 'two', 'three'], 'length'); | |
// => { '3': 2, '5': 1 } | // => { '3': 2, '5': 1 } | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_everycollection-predicate_identity-thisarg"></a>`_.every(collection, | ### <a id="_everycollection-predicate_identity"></a>`_.every(collection, [predic | |
[predicate=_.identity], [thisArg])` | ate=_.identity])` | |
<a href="#_everycollection-predicate_identity-thisarg">#</a> [Ⓢ](https:// | <a href="#_everycollection-predicate_identity">#</a> [Ⓢ](https://github.c | |
github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L5702 "View in source") [$ | om/lodash/lodash/blob/4.0.0/lodash.js#L7337 "View in source") [Ⓣ][1] [&#x | |
C9;][1] | 24C3;](https://www.npmjs.com/package/lodash.every "See the npm package") | |
Checks if `predicate` returns truthy for **all** elements of `collection`. | Checks if `predicate` returns truthy for **all** elements of `collection`. | |
The predicate is bound to `thisArg` and invoked with three arguments; | Iteration is stopped once `predicate` returns falsey. The predicate is | |
(value, index|key, collection). | invoked with three arguments: (value, index|key, collection). | |
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | 1. `collection` *(Array|Object)*: The collection to iterate over. | |
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | |
iteration. If a property name or object is provided it is used to create a "_.p | iteration. | |
roperty" or "_.matches" style callback respectively. | ||
3. `[thisArg]` *(*)*: The `this` binding of `predicate`. | ||
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if all elements pass the predicate check, | *(boolean)*: Returns `true` if all elements pass the predicate check, else `fal | |
else `false`. | se`. | |
#### Example | #### Example | |
```js | ```js | |
_.every([true, 1, null, 'yes']); | _.every([true, 1, null, 'yes'], Boolean); | |
// => false | // => false | |
var users = [ | var users = [ | |
{ 'user': 'barney', 'age': 36 }, | { 'user': 'barney', 'active': false }, | |
{ 'user': 'fred', 'age': 40 } | { 'user': 'fred', 'active': false } | |
]; | ]; | |
// using the "_.property" callback shorthand | // using the `_.matches` iteratee shorthand | |
_.every(users, 'age'); | _.every(users, { 'user': 'barney', 'active': false }); | |
// => false | ||
// using the `_.matchesProperty` iteratee shorthand | ||
_.every(users, ['active', false]); | ||
// => true | // => true | |
// using the "_.matches" callback shorthand | // using the `_.property` iteratee shorthand | |
_.every(users, { 'age': 36 }); | _.every(users, 'active'); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_filtercollection-predicate_identity-thisarg"></a>`_.filter(collectio | ### <a id="_filtercollection-predicate_identity"></a>`_.filter(collection, [pred | |
n, [predicate=_.identity], [thisArg])` | icate=_.identity])` | |
<a href="#_filtercollection-predicate_identity-thisarg">#</a> [Ⓢ](https:/ | <a href="#_filtercollection-predicate_identity">#</a> [Ⓢ](https://github. | |
/github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L5750 "View in source") [ | com/lodash/lodash/blob/4.0.0/lodash.js#L7378 "View in source") [Ⓣ][1] [&# | |
4C9;][1] | x24C3;](https://www.npmjs.com/package/lodash.filter "See the npm package") | |
Iterates over elements of `collection`, returning an array of all elements | Iterates over elements of `collection`, returning an array of all elements | |
`predicate` returns truthy for. The predicate is bound to `thisArg` and | `predicate` returns truthy for. The predicate is invoked with three arguments:<b | |
invoked with three arguments; (value, index|key, collection). | r> | |
(value, index|key, collection). | ||
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | 1. `collection` *(Array|Object)*: The collection to iterate over. | |
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | |
iteration. If a property name or object is provided it is used to create a "_.p | iteration. | |
roperty" or "_.matches" style callback respectively. | ||
3. `[thisArg]` *(*)*: The `this` binding of `predicate`. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the new filtered array. | *(Array)*: Returns the new filtered array. | |
#### Example | #### Example | |
```js | ```js | |
var evens = _.filter([1, 2, 3, 4], function(n) { return n % 2 == 0; }); | ||
// => [2, 4] | ||
var users = [ | var users = [ | |
{ 'user': 'barney', 'age': 36, 'active': false }, | { 'user': 'barney', 'age': 36, 'active': true }, | |
{ 'user': 'fred', 'age': 40, 'active': true } | { 'user': 'fred', 'age': 40, 'active': false } | |
]; | ]; | |
// using the "_.property" callback shorthand | _.filter(users, function(o) { return !o.active; }); | |
_.pluck(_.filter(users, 'active'), 'user'); | // => objects for ['fred'] | |
// => ['fred'] | ||
// using the `_.matches` iteratee shorthand | ||
_.filter(users, { 'age': 36, 'active': true }); | ||
// => objects for ['barney'] | ||
// using the "_.matches" callback shorthand | // using the `_.matchesProperty` iteratee shorthand | |
_.pluck(_.filter(users, { 'age': 36 }), 'user'); | _.filter(users, ['active', false]); | |
// => ['barney'] | // => objects for ['fred'] | |
// using the `_.property` iteratee shorthand | ||
_.filter(users, 'active'); | ||
// => objects for ['barney'] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_findcollection-predicate_identity-thisarg"></a>`_.find(collection, [ | ### <a id="_findcollection-predicate_identity"></a>`_.find(collection, [predicat | |
predicate=_.identity], [thisArg])` | e=_.identity])` | |
<a href="#_findcollection-predicate_identity-thisarg">#</a> [Ⓢ](https://g | <a href="#_findcollection-predicate_identity">#</a> [Ⓢ](https://github.co | |
ithub.com/lodash/lodash/blob/3.0.0/lodash.src.js#L5797 "View in source") [Ɍ | m/lodash/lodash/blob/4.0.0/lodash.js#L7417 "View in source") [Ⓣ][1] [ | |
9;][1] | 4C3;](https://www.npmjs.com/package/lodash.find "See the npm package") | |
Iterates over elements of `collection`, returning the first element | Iterates over elements of `collection`, returning the first element | |
`predicate` returns truthy for. The predicate is bound to `thisArg` and | `predicate` returns truthy for. The predicate is invoked with three arguments:<b | |
invoked with three arguments; (value, index|key, collection). | r> | |
(value, index|key, collection). | ||
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to search. | 1. `collection` *(Array|Object)*: The collection to search. | |
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | |
iteration. If a property name or object is provided it is used to create a "_.p | iteration. | |
roperty" or "_.matches" style callback respectively. | ||
3. `[thisArg]` *(*)*: The `this` binding of `predicate`. | ||
#### Returns | #### Returns | |
*(*)*: Returns the matched element, else `undefined`. | *(*)*: Returns the matched element, else `undefined`. | |
#### Example | #### Example | |
```js | ```js | |
var users = [ | var users = [ | |
{ 'user': 'barney', 'age': 36, 'active': false }, | { 'user': 'barney', 'age': 36, 'active': true }, | |
{ 'user': 'fred', 'age': 40, 'active': true }, | { 'user': 'fred', 'age': 40, 'active': false }, | |
{ 'user': 'pebbles', 'age': 1, 'active': false } | { 'user': 'pebbles', 'age': 1, 'active': true } | |
]; | ]; | |
_.result(_.find(users, function(chr) { return chr.age < 40; }), 'user'); | _.find(users, function(o) { return o.age < 40; }); | |
// => 'barney' | // => object for 'barney' | |
// using the "_.matches" callback shorthand | // using the `_.matches` iteratee shorthand | |
_.result(_.find(users, { 'age': 1 }), 'user'); | _.find(users, { 'age': 1, 'active': true }); | |
// => 'pebbles' | // => object for 'pebbles' | |
// using the "_.property" callback shorthand | // using the `_.matchesProperty` iteratee shorthand | |
_.result(_.find(users, 'active'), 'user'); | _.find(users, ['active', false]); | |
// => 'fred' | // => object for 'fred' | |
// using the `_.property` iteratee shorthand | ||
_.find(users, 'active'); | ||
// => object for 'barney' | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_findlastcollection-predicate_identity-thisarg"></a>`_.findLast(colle | ### <a id="_findlastcollection-predicate_identity"></a>`_.findLast(collection, [ | |
ction, [predicate=_.identity], [thisArg])` | predicate=_.identity])` | |
<a href="#_findlastcollection-predicate_identity-thisarg">#</a> [Ⓢ](https | <a href="#_findlastcollection-predicate_identity">#</a> [Ⓢ](https://githu | |
://github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L5824 "View in source") [&# | b.com/lodash/lodash/blob/4.0.0/lodash.js#L7443 "View in source") [Ⓣ][1] [ | |
x24C9;][1] | Ⓝ](https://www.npmjs.com/package/lodash.findlast "See the npm package") | |
This method is like `_.find` except that it iterates over elements of | This method is like `_.find` except that it iterates over elements of | |
`collection` from right to left. | `collection` from right to left. | |
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to search. | 1. `collection` *(Array|Object)*: The collection to search. | |
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | |
iteration. If a property name or object is provided it is used to create a "_.p | iteration. | |
roperty" or "_.matches" style callback respectively. | ||
3. `[thisArg]` *(*)*: The `this` binding of `predicate`. | ||
#### Returns | #### Returns | |
*(*)*: Returns the matched element, else `undefined`. | *(*)*: Returns the matched element, else `undefined`. | |
#### Example | #### Example | |
```js | ```js | |
_.findLast([1, 2, 3, 4], function(n) { return n % 2 == 1; }); | _.findLast([1, 2, 3, 4], function(n) { | |
return n % 2 == 1; | ||
}); | ||
// => 3 | // => 3 | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_findwherecollection-source"></a>`_.findWhere(collection, source)` | ### <a id="_foreachcollection-iteratee_identity"></a>`_.forEach(collection, [ite | |
<a href="#_findwherecollection-source">#</a> [Ⓢ](https://github.com/lodas | ratee=_.identity])` | |
h/lodash/blob/3.0.0/lodash.src.js#L5853 "View in source") [Ⓣ][1] | <a href="#_foreachcollection-iteratee_identity">#</a> [Ⓢ](https://github. | |
com/lodash/lodash/blob/4.0.0/lodash.js#L7480 "View in source") [Ⓣ][1] [&# | ||
Performs a deep comparison between each element in `collection` and the | x24C3;](https://www.npmjs.com/package/lodash.foreach "See the npm package") | |
source object, returning the first element that has equivalent property | ||
values. | ||
#### Arguments | ||
1. `collection` *(Array|Object|string)*: The collection to search. | ||
2. `source` *(Object)*: The object of property values to match. | ||
#### Returns | ||
*(*)*: Returns the matched element, else `undefined`. | ||
#### Example | ||
```js | ||
var users = [ | ||
{ 'user': 'barney', 'age': 36, 'status': 'busy' }, | ||
{ 'user': 'fred', 'age': 40, 'status': 'busy' } | ||
]; | ||
_.result(_.findWhere(users, { 'status': 'busy' }), 'user'); | ||
// => 'barney' | ||
_.result(_.findWhere(users, { 'age': 40 }), 'user'); | ||
// => 'fred' | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_foreachcollection-iteratee_identity-thisarg"></a>`_.forEach(collecti | ||
on, [iteratee=_.identity], [thisArg])` | ||
<a href="#_foreachcollection-iteratee_identity-thisarg">#</a> [Ⓢ](https:/ | ||
/github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L5883 "View in source") [ | ||
4C9;][1] | ||
Iterates over elements of `collection` invoking `iteratee` for each element. | Iterates over elements of `collection` invoking `iteratee` for each element. | |
The `iteratee` is bound to `thisArg` and invoked with three arguments; | The iteratee is invoked with three arguments: (value, index|key, collection). | |
(value, index|key, collection). Iterator functions may exit iteration early | Iteratee functions may exit iteration early by explicitly returning `false`. | |
by explicitly returning `false`. | <br> | |
*Note:** As with other "Collections" methods, objects with a `length` property | <br> | |
are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn` | **Note:** As with other "Collections" methods, objects with a "length" property | |
may be used for object iteration. | are iterated like arrays. To avoid this behavior use `_.forIn` or `_.forOwn` | |
for object iteration. | ||
#### Aliases | ||
*_.each* | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | 1. `collection` *(Array|Object)*: The collection to iterate over. | |
2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration. | 2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration. | |
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. | ||
#### Returns | #### Returns | |
*(Array|Object|string)*: Returns `collection`. | *(Array|Object)*: Returns `collection`. | |
#### Example | #### Example | |
```js | ```js | |
_([1, 2, 3]).forEach(function(n) { console.log(n); }); | _([1, 2]).forEach(function(value) { | |
// => logs each value from left to right and returns the array | console.log(value); | |
}); | ||
// => logs `1` then `2` | ||
_.forEach({ 'one': 1, 'two': 2, 'three': 3 }, function(n, key) { console.log(n, | _.forEach({ 'a': 1, 'b': 2 }, function(value, key) { | |
key); }); | console.log(key); | |
// => logs each value-key pair and returns the object (iteration order is not gu | }); | |
aranteed) | // => logs 'a' then 'b' (iteration order is not guaranteed) | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_foreachrightcollection-iteratee_identity-thisarg"></a>`_.forEachRigh | ### <a id="_foreachrightcollection-iteratee_identity"></a>`_.forEachRight(collec | |
t(collection, [iteratee=_.identity], [thisArg])` | tion, [iteratee=_.identity])` | |
<a href="#_foreachrightcollection-iteratee_identity-thisarg">#</a> [Ⓢ](ht | <a href="#_foreachrightcollection-iteratee_identity">#</a> [Ⓢ](https://gi | |
tps://github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L5906 "View in source") | thub.com/lodash/lodash/blob/4.0.0/lodash.js#L7504 "View in source") [Ⓣ][1 | |
[Ⓣ][1] | ] [Ⓝ](https://www.npmjs.com/package/lodash.foreachright "See the npm pack | |
age") | ||
This method is like `_.forEach` except that it iterates over elements of | This method is like `_.forEach` except that it iterates over elements of | |
`collection` from right to left. | `collection` from right to left. | |
#### Aliases | ||
*_.eachRight* | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | 1. `collection` *(Array|Object)*: The collection to iterate over. | |
2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration. | 2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration. | |
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. | ||
#### Returns | #### Returns | |
*(Array|Object|string)*: Returns `collection`. | *(Array|Object)*: Returns `collection`. | |
#### Example | #### Example | |
```js | ```js | |
_([1, 2, 3]).forEachRight(function(n) { console.log(n); }).join(','); | _.forEachRight([1, 2], function(value) { | |
// => logs each value from right to left and returns the array | console.log(value); | |
}); | ||
// => logs `2` then `1` | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_groupbycollection-iteratee_identity-thisarg"></a>`_.groupBy(collecti | ### <a id="_groupbycollection-iteratee_identity"></a>`_.groupBy(collection, [ite | |
on, [iteratee=_.identity], [thisArg])` | ratee=_.identity])` | |
<a href="#_groupbycollection-iteratee_identity-thisarg">#</a> [Ⓢ](https:/ | <a href="#_groupbycollection-iteratee_identity">#</a> [Ⓢ](https://github. | |
/github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L5947 "View in source") [ | com/lodash/lodash/blob/4.0.0/lodash.js#L7531 "View in source") [Ⓣ][1] [&# | |
4C9;][1] | x24C3;](https://www.npmjs.com/package/lodash.groupby "See the npm package") | |
Creates an object composed of keys generated from the results of running | Creates an object composed of keys generated from the results of running | |
each element of `collection` through `iteratee`. The corresponding value | each element of `collection` through `iteratee`. The corresponding value | |
of each key is an array of the elements responsible for generating the key. | of each key is an array of the elements responsible for generating the key. | |
The `iteratee` is bound to `thisArg` and invoked with three arguments; | The iteratee is invoked with one argument: (value). | |
(value, index|key, collection). | ||
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | 1. `collection` *(Array|Object)*: The collection to iterate over. | |
2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `[iteratee=_.identity]` *(Function|Object|string)*: The iteratee invoked per | |
iteration. If a property name or object is provided it is used to create a "_.pr | element. | |
operty" or "_.matches" style callback respectively. | ||
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. | ||
#### Returns | #### Returns | |
*(Object)*: Returns the composed aggregate object. | *(Object)*: Returns the composed aggregate object. | |
#### Example | #### Example | |
```js | ```js | |
_.groupBy([4.2, 6.1, 6.4], function(n) { return Math.floor(n); }); | _.groupBy([6.1, 4.2, 6.3], Math.floor); | |
// => { '4': [4.2], '6': [6.1, 6.4] } | // => { '4': [4.2], '6': [6.1, 6.3] } | |
_.groupBy([4.2, 6.1, 6.4], function(n) { return this.floor(n); }, Math); | ||
// => { '4': [4.2], '6': [6.1, 6.4] } | ||
// using the "_.property" callback shorthand | // using the `_.property` iteratee shorthand | |
_.groupBy(['one', 'two', 'three'], 'length'); | _.groupBy(['one', 'two', 'three'], 'length'); | |
// => { '3': ['one', 'two'], '5': ['three'] } | // => { '3': ['one', 'two'], '5': ['three'] } | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_includescollection-target-fromindex0"></a>`_.includes(collection, ta | ### <a id="_includescollection-value-fromindex0"></a>`_.includes(collection, val | |
rget, [fromIndex=0])` | ue, [fromIndex=0])` | |
<a href="#_includescollection-target-fromindex0">#</a> [Ⓢ](https://github | <a href="#_includescollection-value-fromindex0">#</a> [Ⓢ](https://github. | |
.com/lodash/lodash/blob/3.0.0/lodash.src.js#L5604 "View in source") [Ⓣ][1 | com/lodash/lodash/blob/4.0.0/lodash.js#L7567 "View in source") [Ⓣ][1] [&# | |
] | x24C3;](https://www.npmjs.com/package/lodash.includes "See the npm package") | |
Checks if `value` is in `collection` using `SameValueZero` for equality | Checks if `value` is in `collection`. If `collection` is a string it's checked | |
comparisons. If `fromIndex` is negative, it is used as the offset from | for a substring of `value`, otherwise [`SameValueZero`](http://ecma-internationa | |
the end of `collection`. | l.org/ecma-262/6.0/#sec-samevaluezero) | |
*Note:** `SameValueZero` comparisons are like strict equality comparisons, | is used for equality comparisons. If `fromIndex` is negative, it's used as | |
e.g. `===`, except that `NaN` matches `NaN`. See the | the offset from the end of `collection`. | |
[ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezer | ||
o) | ||
for more details. | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to search. | 1. `collection` *(Array|Object|string)*: The collection to search. | |
2. `target` *(*)*: The value to search for. | 2. `value` *(*)*: The value to search for. | |
3. `[fromIndex=0]` *(number)*: The index to search from. | 3. `[fromIndex=0]` *(number)*: The index to search from. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if a matching element is found, else `false`. | *(boolean)*: Returns `true` if `value` is found, else `false`. | |
#### Example | #### Example | |
```js | ```js | |
_.includes([1, 2, 3], 1); | _.includes([1, 2, 3], 1); | |
// => true | // => true | |
_.includes([1, 2, 3], 1, 2); | _.includes([1, 2, 3], 1, 2); | |
// => false | // => false | |
_.includes({ 'user': 'fred', 'age': 40 }, 'fred'); | _.includes({ 'user': 'fred', 'age': 40 }, 'fred'); | |
skipping to change at line 2144 | skipping to change at line 2471 | |
_.includes('pebbles', 'eb'); | _.includes('pebbles', 'eb'); | |
// => true | // => true | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_indexbycollection-iteratee_identity-thisarg"></a>`_.indexBy(collecti | ### <a id="_invokemapcollection-path-args"></a>`_.invokeMap(collection, path, [a | |
on, [iteratee=_.identity], [thisArg])` | rgs])` | |
<a href="#_indexbycollection-iteratee_identity-thisarg">#</a> [Ⓢ](https:/ | <a href="#_invokemapcollection-path-args">#</a> [Ⓢ](https://github.com/lo | |
/github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L5994 "View in source") [ | dash/lodash/blob/4.0.0/lodash.js#L7602 "View in source") [Ⓣ][1] [Ⓝ | |
4C9;][1] | ](https://www.npmjs.com/package/lodash.invokemap "See the npm package") | |
Creates an object composed of keys generated from the results of running | ||
each element of `collection` through `iteratee`. The corresponding value | ||
of each key is the last element responsible for generating the key. The | ||
iteratee function is bound to `thisArg` and invoked with three arguments; | ||
(value, index|key, collection). | ||
If a property name is provided for `predicate` the created "_.property" | Invokes the method at `path` of each element in `collection`, returning | |
style callback returns the property value of the given element. | an array of the results of each invoked method. Any additional arguments | |
are provided to each invoked method. If `methodName` is a function it's | ||
If an object is provided for `predicate` the created "_.matches" style | invoked for, and `this` bound to, each element in `collection`. | |
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | 1. `collection` *(Array|Object)*: The collection to iterate over. | |
2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `path` *(Array|Function|string)*: The path of the method to invoke or the fun | |
iteration. If a property name or object is provided it is used to create a "_.pr | ction invoked per iteration. | |
operty" or "_.matches" style callback respectively. | 3. `[args]` *(...*)*: The arguments to invoke each method with. | |
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. | ||
#### Returns | #### Returns | |
*(Object)*: Returns the composed aggregate object. | *(Array)*: Returns the array of results. | |
#### Example | #### Example | |
```js | ```js | |
var keyData = [ | _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort'); | |
{ 'dir': 'left', 'code': 97 }, | // => [[1, 5, 7], [1, 2, 3]] | |
{ 'dir': 'right', 'code': 100 } | ||
]; | ||
_.indexBy(keyData, 'dir'); | ||
// => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code' | ||
: 100 } } | ||
_.indexBy(keyData, function(object) { return String.fromCharCode(object.code); } | ||
); | ||
// => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } | ||
} | ||
_.indexBy(keyData, function(object) { return this.fromCharCode(object.code); }, | _.invokeMap([123, 456], String.prototype.split, ''); | |
String); | // => [['1', '2', '3'], ['4', '5', '6']] | |
// => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } | ||
} | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_invokecollection-methodname-args"></a>`_.invoke(collection, methodNa | ### <a id="_keybycollection-iteratee_identity"></a>`_.keyBy(collection, [iterate | |
me, [args])` | e=_.identity])` | |
<a href="#_invokecollection-methodname-args">#</a> [Ⓢ](https://github.com | <a href="#_keybycollection-iteratee_identity">#</a> [Ⓢ](https://github.co | |
/lodash/lodash/blob/3.0.0/lodash.src.js#L6020 "View in source") [Ⓣ][1] | m/lodash/lodash/blob/4.0.0/lodash.js#L7642 "View in source") [Ⓣ][1] [ | |
4C3;](https://www.npmjs.com/package/lodash.keyby "See the npm package") | ||
Invokes the method named by `methodName` on each element in `collection`, | Creates an object composed of keys generated from the results of running | |
returning an array of the results of each invoked method. Any additional | each element of `collection` through `iteratee`. The corresponding value | |
arguments are provided to each invoked method. If `methodName` is a function | of each key is the last element responsible for generating the key. The | |
it is invoked for, and `this` bound to, each element in `collection`. | iteratee is invoked with one argument: (value). | |
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | 1. `collection` *(Array|Object)*: The collection to iterate over. | |
2. `methodName` *(Function|string)*: The name of the method to invoke or the fun | 2. `[iteratee=_.identity]` *(Function|Object|string)*: The iteratee invoked per | |
ction invoked per iteration. | element. | |
3. `[args]` *(...*)*: The arguments to invoke the method with. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the array of results. | *(Object)*: Returns the composed aggregate object. | |
#### Example | #### Example | |
```js | ```js | |
_.invoke([[5, 1, 7], [3, 2, 1]], 'sort'); | var keyData = [ | |
// => [[1, 5, 7], [1, 2, 3]] | { 'dir': 'left', 'code': 97 }, | |
{ 'dir': 'right', 'code': 100 } | ||
]; | ||
_.invoke([123, 456], String.prototype.split, ''); | _.keyBy(keyData, 'dir'); | |
// => [['1', '2', '3'], ['4', '5', '6']] | // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code' | |
: 100 } } | ||
_.keyBy(keyData, function(o) { | ||
return String.fromCharCode(o.code); | ||
}); | ||
// => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } | ||
} | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_mapcollection-iteratee_identity-thisarg"></a>`_.map(collection, [ite | ### <a id="_mapcollection-iteratee_identity"></a>`_.map(collection, [iteratee=_. | |
ratee=_.identity], [thisArg])` | identity])` | |
<a href="#_mapcollection-iteratee_identity-thisarg">#</a> [Ⓢ](https://git | <a href="#_mapcollection-iteratee_identity">#</a> [Ⓢ](https://github.com/ | |
hub.com/lodash/lodash/blob/3.0.0/lodash.src.js#L6063 "View in source") [Ⓣ | lodash/lodash/blob/4.0.0/lodash.js#L7687 "View in source") [Ⓣ][1] [Ɍ | |
][1] | 3;](https://www.npmjs.com/package/lodash.map "See the npm package") | |
Creates an array of values by running each element in `collection` through | Creates an array of values by running each element in `collection` through | |
`iteratee`. The `iteratee` is bound to `thisArg` and invoked with three | `iteratee`. The iteratee is invoked with three arguments:<br> | |
arguments; (value, index|key, collection). | (value, index|key, collection). | |
<br> | ||
If a property name is provided for `predicate` the created "_.property" | <br> | |
style callback returns the property value of the given element. | Many lodash methods are guarded to work as iteratees for methods like | |
`_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. | ||
If an object is provided for `predicate` the created "_.matches" style | <br> | |
callback returns `true` for elements that have the properties of the given | <br> | |
object, else `false`. | The guarded methods are:<br> | |
`ary`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, `fill`, | ||
`invert`, `parseInt`, `random`, `range`, `rangeRight`, `slice`, `some`, | ||
`sortBy`, `take`, `takeRight`, `template`, `trim`, `trimEnd`, `trimStart`, | ||
and `words` | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | 1. `collection` *(Array|Object)*: The collection to iterate over. | |
2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per | |
iteration. If a property name or object is provided it is used to create a "_.pr | iteration. | |
operty" or "_.matches" style callback respectively. | ||
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the new mapped array. | *(Array)*: Returns the new mapped array. | |
#### Example | #### Example | |
```js | ```js | |
_.map([1, 2, 3], function(n) { return n * 3; }); | function square(n) { | |
// => [3, 6, 9] | return n * n; | |
} | ||
_.map([1, 2], square); | ||
// => [3, 6] | ||
_.map({ 'one': 1, 'two': 2, 'three': 3 }, function(n) { return n * 3; }); | _.map({ 'a': 1, 'b': 2 }, square); | |
// => [3, 6, 9] (iteration order is not guaranteed) | // => [3, 6] (iteration order is not guaranteed) | |
var users = [ | var users = [ | |
{ 'user': 'barney' }, | { 'user': 'barney' }, | |
{ 'user': 'fred' } | { 'user': 'fred' } | |
]; | ]; | |
// using the "_.property" callback shorthand | // using the `_.property` iteratee shorthand | |
_.map(users, 'user'); | _.map(users, 'user'); | |
// => ['barney', 'fred'] | // => ['barney', 'fred'] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_maxcollection-iteratee-thisarg"></a>`_.max(collection, [iteratee], [ | ### <a id="_orderbycollection-iteratees-_identity-orders"></a>`_.orderBy(collect | |
thisArg])` | ion, [iteratees=[_.identity]], [orders])` | |
<a href="#_maxcollection-iteratee-thisarg">#</a> [Ⓢ](https://github.com/l | <a href="#_orderbycollection-iteratees-_identity-orders">#</a> [Ⓢ](https: | |
odash/lodash/blob/3.0.0/lodash.src.js#L6112 "View in source") [Ⓣ][1] | //github.com/lodash/lodash/blob/4.0.0/lodash.js#L7719 "View in source") [Ⓣ | |
;][1] [Ⓝ](https://www.npmjs.com/package/lodash.orderby "See the npm packa | ||
Gets the maximum value of `collection`. If `collection` is empty or falsey | ge") | |
`-Infinity` is returned. If an iteratee function is provided it is invoked | ||
for each value in `collection` to generate the criterion by which the value | ||
is ranked. The `iteratee` is bound to `thisArg` and invoked with three | ||
arguments; (value, index, collection). | ||
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | ||
1. `collection` *(Array|Object|string)*: The collection to iterate over. | ||
2. `[iteratee]` *(Function|Object|string)*: The function invoked per iteration. | ||
If a property name or object is provided it is used to create a "_.property" or | ||
"_.matches" style callback respectively. | ||
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. | ||
#### Returns | ||
*(*)*: Returns the maximum value. | ||
#### Example | This method is like `_.sortBy` except that it allows specifying the sort | |
```js | orders of the iteratees to sort by. If `orders` is unspecified, all values | |
_.max([4, 2, 8, 6]); | are sorted in ascending order. Otherwise, specify an order of "desc" for | |
// => 8 | descending or "asc" for ascending sort order of corresponding values. | |
_.max([]); | ||
// => -Infinity | ||
var users = [ | ||
{ 'user': 'barney', 'age': 36 }, | ||
{ 'user': 'fred', 'age': 40 } | ||
]; | ||
_.max(users, function(chr) { return chr.age; }); | ||
// => { 'user': 'fred', 'age': 40 }; | ||
// using the "_.property" callback shorthand | ||
_.max(users, 'age'); | ||
// => { 'user': 'fred', 'age': 40 }; | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_mincollection-iteratee-thisarg"></a>`_.min(collection, [iteratee], [ | ||
thisArg])` | ||
<a href="#_mincollection-iteratee-thisarg">#</a> [Ⓢ](https://github.com/l | ||
odash/lodash/blob/3.0.0/lodash.src.js#L6157 "View in source") [Ⓣ][1] | ||
Gets the minimum value of `collection`. If `collection` is empty or falsey | ||
`Infinity` is returned. If an iteratee function is provided it is invoked | ||
for each value in `collection` to generate the criterion by which the value | ||
is ranked. The `iteratee` is bound to `thisArg` and invoked with three | ||
arguments; (value, index, collection). | ||
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | 1. `collection` *(Array|Object)*: The collection to iterate over. | |
2. `[iteratee]` *(Function|Object|string)*: The function invoked per iteration. | 2. `[iteratees=[_.identity]]` *(Function[]|Object[]|string[& | |
If a property name or object is provided it is used to create a "_.property" or | #93;)*: The iteratees to sort by. | |
"_.matches" style callback respectively. | 3. `[orders]` *(string[])*: The sort orders of `iteratees`. | |
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. | ||
#### Returns | #### Returns | |
*(*)*: Returns the minimum value. | *(Array)*: Returns the new sorted array. | |
#### Example | #### Example | |
```js | ```js | |
_.min([4, 2, 8, 6]); | ||
// => 2 | ||
_.min([]); | ||
// => Infinity | ||
var users = [ | var users = [ | |
{ 'user': 'barney', 'age': 36 }, | { 'user': 'fred', 'age': 48 }, | |
{ 'user': 'fred', 'age': 40 } | { 'user': 'barney', 'age': 34 }, | |
{ 'user': 'fred', 'age': 42 }, | ||
{ 'user': 'barney', 'age': 36 } | ||
]; | ]; | |
_.min(users, function(chr) { return chr.age; }); | // sort by `user` in ascending order and by `age` in descending order | |
// => { 'user': 'barney', 'age': 36 }; | _.orderBy(users, ['user', 'age'], ['asc', 'desc']); | |
// => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]] | ||
// using the "_.property" callback shorthand | ||
_.min(users, 'age'); | ||
// => { 'user': 'barney', 'age': 36 }; | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_partitioncollection-predicate_identity-thisarg"></a>`_.partition(col | ### <a id="_partitioncollection-predicate_identity"></a>`_.partition(collection, | |
lection, [predicate=_.identity], [thisArg])` | [predicate=_.identity])` | |
<a href="#_partitioncollection-predicate_identity-thisarg">#</a> [Ⓢ](http | <a href="#_partitioncollection-predicate_identity">#</a> [Ⓢ](https://gith | |
s://github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L6203 "View in source") [& | ub.com/lodash/lodash/blob/4.0.0/lodash.js#L7768 "View in source") [Ⓣ][1] | |
#x24C9;][1] | [Ⓝ](https://www.npmjs.com/package/lodash.partition "See the npm package") | |
Creates an array of elements split into two groups, the first of which | Creates an array of elements split into two groups, the first of which | |
contains elements `predicate` returns truthy for, while the second of which | contains elements `predicate` returns truthy for, while the second of which | |
contains elements `predicate` returns falsey for. The predicate is bound | contains elements `predicate` returns falsey for. The predicate is invoked | |
to `thisArg` and invoked with three arguments; (value, index|key, collection). | with three arguments: (value, index|key, collection). | |
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | 1. `collection` *(Array|Object)*: The collection to iterate over. | |
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | |
iteration. If a property name or object is provided it is used to create a "_.p | iteration. | |
roperty" or "_.matches" style callback respectively. | ||
3. `[thisArg]` *(*)*: The `this` binding of `predicate`. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the array of grouped elements. | *(Array)*: Returns the array of grouped elements. | |
#### Example | #### Example | |
```js | ```js | |
_.partition([1, 2, 3], function(n) { return n % 2; }); | ||
// => [[1, 3], [2]] | ||
_.partition([1.2, 2.3, 3.4], function(n) { return this.floor(n) % 2; }, Math); | ||
// => [[1, 3], [2]] | ||
var users = [ | var users = [ | |
{ 'user': 'barney', 'age': 36, 'active': false }, | { 'user': 'barney', 'age': 36, 'active': false }, | |
{ 'user': 'fred', 'age': 40, 'active': true }, | { 'user': 'fred', 'age': 40, 'active': true }, | |
{ 'user': 'pebbles', 'age': 1, 'active': false } | { 'user': 'pebbles', 'age': 1, 'active': false } | |
]; | ]; | |
// using the "_.matches" callback shorthand | _.partition(users, function(o) { return o.active; }); | |
_.map(_.partition(users, { 'age': 1 }), function(array) { return _.pluck(array, | // => objects for [['fred'], ['barney', 'pebbles']] | |
'user'); }); | ||
// => [['pebbles'], ['barney', 'fred']] | ||
// using the "_.property" callback shorthand | ||
_.map(_.partition(users, 'active'), function(array) { return _.pluck(array, 'use | ||
r'); }); | ||
// => [['fred'], ['barney', 'pebbles']] | ||
``` | ||
* * * | ||
<!-- /div --> | // using the `_.matches` iteratee shorthand | |
_.partition(users, { 'age': 1, 'active': false }); | ||
<!-- div --> | // => objects for [['pebbles'], ['barney', 'fred']] | |
### <a id="_pluckcollection-key"></a>`_.pluck(collection, key)` | ||
<a href="#_pluckcollection-key">#</a> [Ⓢ](https://github.com/lodash/lodas | ||
h/blob/3.0.0/lodash.src.js#L6230 "View in source") [Ⓣ][1] | ||
Gets the value of `key` from all elements in `collection`. | ||
#### Arguments | ||
1. `collection` *(Array|Object|string)*: The collection to iterate over. | ||
2. `key` *(string)*: The key of the property to pluck. | ||
#### Returns | ||
*(Array)*: Returns the property values. | ||
#### Example | ||
```js | ||
var users = [ | ||
{ 'user': 'barney', 'age': 36 }, | ||
{ 'user': 'fred', 'age': 40 } | ||
]; | ||
_.pluck(users, 'user'); | // using the `_.matchesProperty` iteratee shorthand | |
// => ['barney', 'fred'] | _.partition(users, ['active', false]); | |
// => objects for [['barney', 'pebbles'], ['fred']] | ||
var userIndex = _.indexBy(users, 'user'); | // using the `_.property` iteratee shorthand | |
_.pluck(userIndex, 'age'); | _.partition(users, 'active'); | |
// => [36, 40] (iteration order is not guaranteed) | // => objects for [['fred'], ['barney', 'pebbles']] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_reducecollection-iteratee_identity-accumulator-thisarg"></a>`_.reduc | ### <a id="_reducecollection-iteratee_identity-accumulator"></a>`_.reduce(collec | |
e(collection, [iteratee=_.identity], [accumulator], [thisArg])` | tion, [iteratee=_.identity], [accumulator])` | |
<a href="#_reducecollection-iteratee_identity-accumulator-thisarg">#</a> [Ɍ | <a href="#_reducecollection-iteratee_identity-accumulator">#</a> [Ⓢ](http | |
8;](https://github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L6262 "View in sou | s://github.com/lodash/lodash/blob/4.0.0/lodash.js#L7807 "View in source") [$ | |
rce") [Ⓣ][1] | C9;][1] [Ⓝ](https://www.npmjs.com/package/lodash.reduce "See the npm pack | |
age") | ||
Reduces `collection` to a value which is the accumulated result of running | Reduces `collection` to a value which is the accumulated result of running | |
each element in `collection` through `iteratee`, where each successive | each element in `collection` through `iteratee`, where each successive | |
invocation is supplied the return value of the previous. If `accumulator` | invocation is supplied the return value of the previous. If `accumulator` | |
is not provided the first element of `collection` is used as the initial | is not provided the first element of `collection` is used as the initial | |
value. The `iteratee` is bound to `thisArg`and invoked with four arguments; | value. The iteratee is invoked with four arguments:<br> | |
(accumulator, value, index|key, collection). | (accumulator, value, index|key, collection). | |
<br> | ||
<br> | ||
Many lodash methods are guarded to work as iteratees for methods like | ||
`_.reduce`, `_.reduceRight`, and `_.transform`. | ||
<br> | ||
<br> | ||
The guarded methods are:<br> | ||
`assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`, | ||
and `sortBy` | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | 1. `collection` *(Array|Object)*: The collection to iterate over. | |
2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration. | 2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration. | |
3. `[accumulator]` *(*)*: The initial value. | 3. `[accumulator]` *(*)*: The initial value. | |
4. `[thisArg]` *(*)*: The `this` binding of `iteratee`. | ||
#### Returns | #### Returns | |
*(*)*: Returns the accumulated value. | *(*)*: Returns the accumulated value. | |
#### Example | #### Example | |
```js | ```js | |
var sum = _.reduce([1, 2, 3], function(sum, n) { return sum + n; }); | _.reduce([1, 2], function(sum, n) { | |
// => 6 | return sum + n; | |
}); | ||
// => 3 | ||
var mapped = _.reduce({ 'a': 1, 'b': 2, 'c': 3 }, function(result, n, key) { | _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { | |
result[key] = n * 3; | (result[value] || (result[value] = [])).push(key); | |
return result; | return result; | |
}, {}); | }, {}); | |
// => { 'a': 3, 'b': 6, 'c': 9 } (iteration order is not guaranteed) | // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed) | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_reducerightcollection-iteratee_identity-accumulator-thisarg"></a>`_. | ### <a id="_reducerightcollection-iteratee_identity-accumulator"></a>`_.reduceRi | |
reduceRight(collection, [iteratee=_.identity], [accumulator], [thisArg])` | ght(collection, [iteratee=_.identity], [accumulator])` | |
<a href="#_reducerightcollection-iteratee_identity-accumulator-thisarg">#</a> [& | <a href="#_reducerightcollection-iteratee_identity-accumulator">#</a> [Ⓢ] | |
#x24C8;](https://github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L6286 "View i | (https://github.com/lodash/lodash/blob/4.0.0/lodash.js#L7834 "View in source") [ | |
n source") [Ⓣ][1] | Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.reduceright "See th | |
e npm package") | ||
This method is like `_.reduce` except that it iterates over elements of | This method is like `_.reduce` except that it iterates over elements of | |
`collection` from right to left. | `collection` from right to left. | |
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | 1. `collection` *(Array|Object)*: The collection to iterate over. | |
2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration. | 2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration. | |
3. `[accumulator]` *(*)*: The initial value. | 3. `[accumulator]` *(*)*: The initial value. | |
4. `[thisArg]` *(*)*: The `this` binding of `iteratee`. | ||
#### Returns | #### Returns | |
*(*)*: Returns the accumulated value. | *(*)*: Returns the accumulated value. | |
#### Example | #### Example | |
```js | ```js | |
var array = [[0, 1], [2, 3], [4, 5]]; | var array = [[0, 1], [2, 3], [4, 5]]; | |
_.reduceRight(array, function(flattened, other) { return flattened.concat(other) | ||
; }, []); | _.reduceRight(array, function(flattened, other) { | |
return flattened.concat(other); | ||
}, []); | ||
// => [4, 5, 2, 3, 0, 1] | // => [4, 5, 2, 3, 0, 1] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_rejectcollection-predicate_identity-thisarg"></a>`_.reject(collectio | ### <a id="_rejectcollection-predicate_identity"></a>`_.reject(collection, [pred | |
n, [predicate=_.identity], [thisArg])` | icate=_.identity])` | |
<a href="#_rejectcollection-predicate_identity-thisarg">#</a> [Ⓢ](https:/ | <a href="#_rejectcollection-predicate_identity">#</a> [Ⓢ](https://github. | |
/github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L6329 "View in source") [ | com/lodash/lodash/blob/4.0.0/lodash.js#L7873 "View in source") [Ⓣ][1] [&# | |
4C9;][1] | x24C3;](https://www.npmjs.com/package/lodash.reject "See the npm package") | |
The opposite of `_.filter`; this method returns the elements of `collection` | The opposite of `_.filter`; this method returns the elements of `collection` | |
that `predicate` does **not** return truthy for. | that `predicate` does **not** return truthy for. | |
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | 1. `collection` *(Array|Object)*: The collection to iterate over. | |
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | 2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | |
iteration. If a property name or object is provided it is used to create a "_.p | iteration. | |
roperty" or "_.matches" style callback respectively. | ||
3. `[thisArg]` *(*)*: The `this` binding of `predicate`. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the new filtered array. | *(Array)*: Returns the new filtered array. | |
#### Example | #### Example | |
```js | ```js | |
var odds = _.reject([1, 2, 3, 4], function(n) { return n % 2 == 0; }); | ||
// => [1, 3] | ||
var users = [ | var users = [ | |
{ 'user': 'barney', 'age': 36, 'active': false }, | { 'user': 'barney', 'age': 36, 'active': false }, | |
{ 'user': 'fred', 'age': 40, 'active': true } | { 'user': 'fred', 'age': 40, 'active': true } | |
]; | ]; | |
// using the "_.property" callback shorthand | _.reject(users, function(o) { return !o.active; }); | |
_.pluck(_.reject(users, 'active'), 'user'); | // => objects for ['fred'] | |
// => ['barney'] | ||
// using the "_.matches" callback shorthand | // using the `_.matches` iteratee shorthand | |
_.pluck(_.reject(users, { 'age': 36 }), 'user'); | _.reject(users, { 'age': 40, 'active': true }); | |
// => ['fred'] | // => objects for ['barney'] | |
// using the `_.matchesProperty` iteratee shorthand | ||
_.reject(users, ['active', false]); | ||
// => objects for ['fred'] | ||
// using the `_.property` iteratee shorthand | ||
_.reject(users, 'active'); | ||
// => objects for ['barney'] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_samplecollection-n"></a>`_.sample(collection, [n])` | ### <a id="_samplecollection"></a>`_.sample(collection)` | |
<a href="#_samplecollection-n">#</a> [Ⓢ](https://github.com/lodash/lodash | <a href="#_samplecollection">#</a> [Ⓢ](https://github.com/lodash/lodash/b | |
/blob/3.0.0/lodash.src.js#L6355 "View in source") [Ⓣ][1] | lob/4.0.0/lodash.js#L7894 "View in source") [Ⓣ][1] [Ⓝ](https://www | |
.npmjs.com/package/lodash.sample "See the npm package") | ||
Gets a random element or `n` random elements from a collection. | Gets a random element from `collection`. | |
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to sample. | 1. `collection` *(Array|Object)*: The collection to sample. | |
2. `[n]` *(number)*: The number of elements to sample. | ||
#### Returns | #### Returns | |
*(*)*: Returns the random sample(s). | *(*)*: Returns the random element. | |
#### Example | #### Example | |
```js | ```js | |
_.sample([1, 2, 3, 4]); | _.sample([1, 2, 3, 4]); | |
// => 2 | // => 2 | |
_.sample([1, 2, 3, 4], 2); | ||
// => [3, 1] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_shufflecollection"></a>`_.shuffle(collection)` | ### <a id="_samplesizecollection-n0"></a>`_.sampleSize(collection, [n=0])` | |
<a href="#_shufflecollection">#</a> [Ⓢ](https://github.com/lodash/lodash/ | <a href="#_samplesizecollection-n0">#</a> [Ⓢ](https://github.com/lodash/l | |
blob/3.0.0/lodash.src.js#L6381 "View in source") [Ⓣ][1] | odash/blob/4.0.0/lodash.js#L7915 "View in source") [Ⓣ][1] [Ⓝ](http | |
s://www.npmjs.com/package/lodash.samplesize "See the npm package") | ||
Creates an array of shuffled values, using a version of the Fisher-Yates | Gets `n` random elements from `collection`. | |
shuffle. See [Wikipedia](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle) | ||
for more details. | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to shuffle. | 1. `collection` *(Array|Object)*: The collection to sample. | |
2. `[n=0]` *(number)*: The number of elements to sample. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the new shuffled array. | *(Array)*: Returns the random elements. | |
#### Example | #### Example | |
```js | ```js | |
_.shuffle([1, 2, 3, 4]); | _.sampleSize([1, 2, 3, 4], 2); | |
// => [4, 1, 3, 2] | // => [3, 1] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_sizecollection"></a>`_.size(collection)` | ### <a id="_shufflecollection"></a>`_.shuffle(collection)` | |
<a href="#_sizecollection">#</a> [Ⓢ](https://github.com/lodash/lodash/blo | <a href="#_shufflecollection">#</a> [Ⓢ](https://github.com/lodash/lodash/ | |
b/3.0.0/lodash.src.js#L6418 "View in source") [Ⓣ][1] | blob/4.0.0/lodash.js#L7947 "View in source") [Ⓣ][1] [Ⓝ](https://ww | |
w.npmjs.com/package/lodash.shuffle "See the npm package") | ||
Gets the size of `collection` by returning `collection.length` for | Creates an array of shuffled values, using a version of the | |
array-like values or the number of own enumerable properties for objects. | [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle). | |
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to inspect. | 1. `collection` *(Array|Object)*: The collection to shuffle. | |
#### Returns | #### Returns | |
*(number)*: Returns the size of `collection`. | *(Array)*: Returns the new shuffled array. | |
#### Example | #### Example | |
```js | ```js | |
_.size([1, 2]); | _.shuffle([1, 2, 3, 4]); | |
// => 2 | // => [4, 1, 3, 2] | |
_.size({ 'one': 1, 'two': 2, 'three': 3 }); | ||
// => 3 | ||
_.size('pebbles'); | ||
// => 7 | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_somecollection-predicate_identity-thisarg"></a>`_.some(collection, [ | ### <a id="_sizecollection"></a>`_.size(collection)` | |
predicate=_.identity], [thisArg])` | <a href="#_sizecollection">#</a> [Ⓢ](https://github.com/lodash/lodash/blo | |
<a href="#_somecollection-predicate_identity-thisarg">#</a> [Ⓢ](https://g | b/4.0.0/lodash.js#L7971 "View in source") [Ⓣ][1] [Ⓝ](https://www.n | |
ithub.com/lodash/lodash/blob/3.0.0/lodash.src.js#L6465 "View in source") [Ɍ | pmjs.com/package/lodash.size "See the npm package") | |
9;][1] | ||
Checks if `predicate` returns truthy for **any** element of `collection`. | ||
The function returns as soon as it finds a passing value and does not iterate | ||
over the entire collection. The predicate is bound to `thisArg` and invoked | ||
with three arguments; (value, index|key, collection). | ||
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | Gets the size of `collection` by returning its length for array-like | |
callback returns `true` for elements that have the properties of the given | values or the number of own enumerable properties for objects. | |
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | 1. `collection` *(Array|Object)*: The collection to inspect. | |
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | ||
iteration. If a property name or object is provided it is used to create a "_.p | ||
roperty" or "_.matches" style callback respectively. | ||
3. `[thisArg]` *(*)*: The `this` binding of `predicate`. | ||
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if any element passes the predicate check, | *(number)*: Returns the collection size. | |
else `false`. | ||
#### Example | #### Example | |
```js | ```js | |
_.some([null, 0, 'yes', false], Boolean); | _.size([1, 2, 3]); | |
// => true | // => 3 | |
var users = [ | ||
{ 'user': 'barney', 'age': 36, 'active': false }, | ||
{ 'user': 'fred', 'age': 40, 'active': true } | ||
]; | ||
// using the "_.property" callback shorthand | _.size({ 'a': 1, 'b': 2 }); | |
_.some(users, 'active'); | // => 2 | |
// => true | ||
// using the "_.matches" callback shorthand | _.size('pebbles'); | |
_.some(users, { 'age': 1 }); | // => 7 | |
// => false | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_sortbycollection-iteratee_identity-thisarg"></a>`_.sortBy(collection | ### <a id="_somecollection-predicate_identity"></a>`_.some(collection, [predicat | |
, [iteratee=_.identity], [thisArg])` | e=_.identity])` | |
<a href="#_sortbycollection-iteratee_identity-thisarg">#</a> [Ⓢ](https:// | <a href="#_somecollection-predicate_identity">#</a> [Ⓢ](https://github.co | |
github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L6514 "View in source") [$ | m/lodash/lodash/blob/4.0.0/lodash.js#L8016 "View in source") [Ⓣ][1] [ | |
C9;][1] | 4C3;](https://www.npmjs.com/package/lodash.some "See the npm package") | |
Creates an array of elements, sorted in ascending order by the results of | Checks if `predicate` returns truthy for **any** element of `collection`. | |
running each element in a collection through `iteratee`. This method performs | Iteration is stopped once `predicate` returns truthy. The predicate is | |
a stable sort, that is, it preserves the original sort order of equal elements. | invoked with three arguments: (value, index|key, collection). | |
The `iteratee` is bound to `thisArg` and invoked with three arguments; | ||
(value, index|key, collection). | ||
If a property name is provided for `predicate` the created "_.property" | ||
style callback returns the property value of the given element. | ||
If an object is provided for `predicate` the created "_.matches" style | ||
callback returns `true` for elements that have the properties of the given | ||
object, else `false`. | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to iterate over. | 1. `collection` *(Array|Object)*: The collection to iterate over. | |
2. `[iteratee=_.identity]` *(Array|Function|Object|string)*: The function invoke | 2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per | |
d per iteration. If a property name or an object is provided it is used to creat | iteration. | |
e a "_.property" or "_.matches" style callback respectively. | ||
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the new sorted array. | *(boolean)*: Returns `true` if any element passes the predicate check, else `fa lse`. | |
#### Example | #### Example | |
```js | ```js | |
_.sortBy([1, 2, 3], function(n) { return Math.sin(n); }); | _.some([null, 0, 'yes', false], Boolean); | |
// => [3, 1, 2] | // => true | |
_.sortBy([1, 2, 3], function(n) { return this.sin(n); }, Math); | ||
// => [3, 1, 2] | ||
var users = [ | var users = [ | |
{ 'user': 'fred' }, | { 'user': 'barney', 'active': true }, | |
{ 'user': 'pebbles' }, | { 'user': 'fred', 'active': false } | |
{ 'user': 'barney' } | ||
]; | ]; | |
// using the "_.property" callback shorthand | // using the `_.matches` iteratee shorthand | |
_.pluck(_.sortBy(users, 'user'), 'user'); | _.some(users, { 'user': 'barney', 'active': false }); | |
// => ['barney', 'fred', 'pebbles'] | // => false | |
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_sortbyallcollection-props"></a>`_.sortByAll(collection, props)` | ||
<a href="#_sortbyallcollection-props">#</a> [Ⓢ](https://github.com/lodash | ||
/lodash/blob/3.0.0/lodash.src.js#L6552 "View in source") [Ⓣ][1] | ||
This method is like `_.sortBy` except that it sorts by property names | ||
instead of an iteratee function. | ||
#### Arguments | ||
1. `collection` *(Array|Object|string)*: The collection to iterate over. | ||
2. `props` *(...(string|string[])*: The property names to sort by, speci | ||
fied as individual property names or arrays of property names. | ||
#### Returns | ||
*(Array)*: Returns the new sorted array. | ||
#### Example | // using the `_.matchesProperty` iteratee shorthand | |
```js | _.some(users, ['active', false]); | |
var users = [ | // => true | |
{ 'user': 'barney', 'age': 36 }, | ||
{ 'user': 'fred', 'age': 40 }, | ||
{ 'user': 'barney', 'age': 26 }, | ||
{ 'user': 'fred', 'age': 30 } | ||
]; | ||
_.map(_.sortByAll(users, ['user', 'age']), _.values); | // using the `_.property` iteratee shorthand | |
// => [['barney', 26], ['barney', 36], ['fred', 30], ['fred', 40]] | _.some(users, 'active'); | |
// => true | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_wherecollection-source"></a>`_.where(collection, source)` | ### <a id="_sortbycollection-iteratees-_identity"></a>`_.sortBy(collection, [ite | |
<a href="#_wherecollection-source">#</a> [Ⓢ](https://github.com/lodash/lo | ratees=[_.identity]])` | |
dash/blob/3.0.0/lodash.src.js#L6601 "View in source") [Ⓣ][1] | <a href="#_sortbycollection-iteratees-_identity">#</a> [Ⓢ](https://github | |
.com/lodash/lodash/blob/4.0.0/lodash.js#L8057 "View in source") [Ⓣ][1] [& | ||
#x24C3;](https://www.npmjs.com/package/lodash.sortby "See the npm package") | ||
Performs a deep comparison between each element in `collection` and the | Creates an array of elements, sorted in ascending order by the results of | |
source object, returning an array of all elements that have equivalent | running each element in a collection through each iteratee. This method | |
property values. | performs a stable sort, that is, it preserves the original sort order of | |
equal elements. The iteratees are invoked with one argument: (value). | ||
#### Arguments | #### Arguments | |
1. `collection` *(Array|Object|string)*: The collection to search. | 1. `collection` *(Array|Object)*: The collection to iterate over. | |
2. `source` *(Object)*: The object of property values to match. | 2. `[iteratees=[_.identity]]` *(...(Function|Function[]|Object|Object	 | |
1;]|string|string[])*: The iteratees to sort by, specified individu | ||
ally or in arrays. | ||
#### Returns | #### Returns | |
*(Array)*: Returns the new filtered array. | *(Array)*: Returns the new sorted array. | |
#### Example | #### Example | |
```js | ```js | |
var users = [ | var users = [ | |
{ 'user': 'barney', 'age': 36, 'status': 'busy', 'pets': ['hoppy'] }, | { 'user': 'fred', 'age': 48 }, | |
{ 'user': 'fred', 'age': 40, 'status': 'busy', 'pets': ['baby puss', 'dino'] | { 'user': 'barney', 'age': 36 }, | |
} | { 'user': 'fred', 'age': 42 }, | |
{ 'user': 'barney', 'age': 34 } | ||
]; | ]; | |
_.pluck(_.where(users, { 'age': 36 }), 'user'); | _.sortBy(users, function(o) { return o.user; }); | |
// => ['barney'] | // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]] | |
_.pluck(_.where(users, { 'pets': ['dino'] }), 'user'); | _.sortBy(users, ['user', 'age']); | |
// => ['fred'] | // => objects for [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]] | |
_.pluck(_.where(users, { 'status': 'busy' }), 'user'); | _.sortBy(users, 'user', function(o) { | |
// => ['barney', 'fred'] | return Math.floor(o.age / 10); | |
}); | ||
// => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
## `“Date” Methods` | ## `“Date” Methods` | |
<!-- div --> | <!-- div --> | |
### <a id="_now"></a>`_.now` | ### <a id="_now"></a>`_.now()` | |
<a href="#_now">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.0.0/lod | <a href="#_now">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4.0.0/lod | |
ash.src.js#L6619 "View in source") [Ⓣ][1] | ash.js#L8088 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/pa | |
ckage/lodash.now "See the npm package") | ||
Gets the number of milliseconds that have elapsed since the Unix epoch | Gets the timestamp of the number of milliseconds that have elapsed since | |
(1 January 1970 00:00:00 UTC). | the Unix epoch (1 January 1970 00:00:00 UTC). | |
#### Returns | ||
*(number)*: Returns the timestamp. | ||
#### Example | #### Example | |
```js | ```js | |
_.defer(function(stamp) { console.log(_.now() - stamp); }, _.now()); | _.defer(function(stamp) { | |
console.log(_.now() - stamp); | ||
}, _.now()); | ||
// => logs the number of milliseconds it took for the deferred function to be in voked | // => logs the number of milliseconds it took for the deferred function to be in voked | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
## `“Function” Methods` | ## `“Function” Methods` | |
<!-- div --> | <!-- div --> | |
### <a id="_aftern-func"></a>`_.after(n, func)` | ### <a id="_aftern-func"></a>`_.after(n, func)` | |
<a href="#_aftern-func">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3 .0.0/lodash.src.js#L6648 "View in source") [Ⓣ][1] | <a href="#_aftern-func">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4 .0.0/lodash.js#L8115 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmj s.com/package/lodash.after "See the npm package") | |
The opposite of `_.before`; this method creates a function that invokes | The opposite of `_.before`; this method creates a function that invokes | |
`func` once it is called `n` or more times. | `func` once it's called `n` or more times. | |
#### Arguments | #### Arguments | |
1. `n` *(number)*: The number of calls before `func` is invoked. | 1. `n` *(number)*: The number of calls before `func` is invoked. | |
2. `func` *(Function)*: The function to restrict. | 2. `func` *(Function)*: The function to restrict. | |
#### Returns | #### Returns | |
*(Function)*: Returns the new restricted function. | *(Function)*: Returns the new restricted function. | |
#### Example | #### Example | |
```js | ```js | |
skipping to change at line 2859 | skipping to change at line 3030 | |
asyncSave({ 'type': type, 'complete': done }); | asyncSave({ 'type': type, 'complete': done }); | |
}); | }); | |
// => logs 'done saving!' after the two async saves have completed | // => logs 'done saving!' after the two async saves have completed | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_aryfunc"></a>`_.ary(func)` | ### <a id="_aryfunc-nfunclength"></a>`_.ary(func, [n=func.length])` | |
<a href="#_aryfunc">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.0.0 | <a href="#_aryfunc-nfunclength">#</a> [Ⓢ](https://github.com/lodash/lodas | |
/lodash.src.js#L6682 "View in source") [Ⓣ][1] | h/blob/4.0.0/lodash.js#L8143 "View in source") [Ⓣ][1] [Ⓝ](https:// | |
www.npmjs.com/package/lodash.ary "See the npm package") | ||
Creates a function that accepts up to `n` arguments ignoring any | Creates a function that accepts up to `n` arguments, ignoring any | |
additional arguments. | additional arguments. | |
#### Arguments | #### Arguments | |
1. `func` *(Function)*: The function to cap arguments for. | 1. `func` *(Function)*: The function to cap arguments for. | |
2. `[n=func.length]` *(number)*: The arity cap. | 2. `[n=func.length]` *(number)*: The arity cap. | |
#### Returns | #### Returns | |
*(Function)*: Returns the new function. | *(Function)*: Returns the new function. | |
#### Example | #### Example | |
skipping to change at line 2884 | skipping to change at line 3055 | |
_.map(['6', '8', '10'], _.ary(parseInt, 1)); | _.map(['6', '8', '10'], _.ary(parseInt, 1)); | |
// => [6, 8, 10] | // => [6, 8, 10] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_beforen-func"></a>`_.before(n, func)` | ### <a id="_beforen-func"></a>`_.before(n, func)` | |
<a href="#_beforen-func">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 3.0.0/lodash.src.js#L6706 "View in source") [Ⓣ][1] | <a href="#_beforen-func">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 4.0.0/lodash.js#L8165 "View in source") [Ⓣ][1] [Ⓝ](https://www.npm js.com/package/lodash.before "See the npm package") | |
Creates a function that invokes `func`, with the `this` binding and arguments | Creates a function that invokes `func`, with the `this` binding and arguments | |
of the created function, while it is called less than `n` times. Subsequent | of the created function, while it's called less than `n` times. Subsequent | |
calls to the created function return the result of the last `func` invocation. | calls to the created function return the result of the last `func` invocation. | |
#### Arguments | #### Arguments | |
1. `n` *(number)*: The number of calls at which `func` is no longer invoked. | 1. `n` *(number)*: The number of calls at which `func` is no longer invoked. | |
2. `func` *(Function)*: The function to restrict. | 2. `func` *(Function)*: The function to restrict. | |
#### Returns | #### Returns | |
*(Function)*: Returns the new restricted function. | *(Function)*: Returns the new restricted function. | |
#### Example | #### Example | |
```js | ```js | |
jQuery('#add').on('click', _.before(5, addContactToList)); | jQuery(element).on('click', _.before(5, addContactToList)); | |
// => allows adding up to 4 contacts to the list | // => allows adding up to 4 contacts to the list | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_bindfunc-thisarg-args"></a>`_.bind(func, thisArg, [args])` | ### <a id="_bindfunc-thisarg-partials"></a>`_.bind(func, thisArg, [partials])` | |
<a href="#_bindfunc-thisarg-args">#</a> [Ⓢ](https://github.com/lodash/lod | <a href="#_bindfunc-thisarg-partials">#</a> [Ⓢ](https://github.com/lodash | |
ash/blob/3.0.0/lodash.src.js#L6762 "View in source") [Ⓣ][1] | /lodash/blob/4.0.0/lodash.js#L8217 "View in source") [Ⓣ][1] [Ⓝ](ht | |
tps://www.npmjs.com/package/lodash.bind "See the npm package") | ||
Creates a function that invokes `func` with the `this` binding of `thisArg` | Creates a function that invokes `func` with the `this` binding of `thisArg` | |
and prepends any additional `_.bind` arguments to those provided to the | and prepends any additional `_.bind` arguments to those provided to the | |
bound function. | bound function. | |
<br> | ||
<br> | ||
The `_.bind.placeholder` value, which defaults to `_` in monolithic builds, | The `_.bind.placeholder` value, which defaults to `_` in monolithic builds, | |
may be used as a placeholder for partially applied arguments. | may be used as a placeholder for partially applied arguments. | |
*Note:** Unlike native `Function#bind` this method does not set the `length` | <br> | |
<br> | ||
**Note:** Unlike native `Function#bind` this method doesn't set the "length" | ||
property of bound functions. | property of bound functions. | |
#### Arguments | #### Arguments | |
1. `func` *(Function)*: The function to bind. | 1. `func` *(Function)*: The function to bind. | |
2. `thisArg` *(*)*: The `this` binding of `func`. | 2. `thisArg` *(*)*: The `this` binding of `func`. | |
3. `[args]` *(...*)*: The arguments to be partially applied. | 3. `[partials]` *(...*)*: The arguments to be partially applied. | |
#### Returns | #### Returns | |
*(Function)*: Returns the new bound function. | *(Function)*: Returns the new bound function. | |
#### Example | #### Example | |
```js | ```js | |
var greet = function(greeting, punctuation) { | var greet = function(greeting, punctuation) { | |
return greeting + ' ' + this.user + punctuation; | return greeting + ' ' + this.user + punctuation; | |
}; | }; | |
skipping to change at line 2951 | skipping to change at line 3125 | |
var bound = _.bind(greet, object, _, '!'); | var bound = _.bind(greet, object, _, '!'); | |
bound('hi'); | bound('hi'); | |
// => 'hi fred!' | // => 'hi fred!' | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_bindallobject-methodnames"></a>`_.bindAll(object, [methodNames])` | ### <a id="_bindkeyobject-key-partials"></a>`_.bindKey(object, key, [partials])` | |
<a href="#_bindallobject-methodnames">#</a> [Ⓢ](https://github.com/lodash | <a href="#_bindkeyobject-key-partials">#</a> [Ⓢ](https://github.com/lodas | |
/lodash/blob/3.0.0/lodash.src.js#L6799 "View in source") [Ⓣ][1] | h/lodash/blob/4.0.0/lodash.js#L8270 "View in source") [Ⓣ][1] [Ⓝ](h | |
ttps://www.npmjs.com/package/lodash.bindkey "See the npm package") | ||
Binds methods of an object to the object itself, overwriting the existing | ||
method. Method names may be specified as individual arguments or as arrays | ||
of method names. If no method names are provided all enumerable function | ||
properties, own and inherited, of `object` are bound. | ||
*Note:** This method does not set the `length` property of bound functions. | ||
#### Arguments | ||
1. `object` *(Object)*: The object to bind and assign the bound methods to. | ||
2. `[methodNames]` *(...(string|string[])*: The object method names to b | ||
ind, specified as individual method names or arrays of method names. | ||
#### Returns | ||
*(Object)*: Returns `object`. | ||
#### Example | ||
```js | ||
var view = { | ||
'label': 'docs', | ||
'onClick': function() { console.log('clicked ' + this.label); } | ||
}; | ||
_.bindAll(view); | ||
jQuery('#docs').on('click', view.onClick); | ||
// => logs 'clicked docs' when the element is clicked | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_bindkeyobject-key-args"></a>`_.bindKey(object, key, [args])` | ||
<a href="#_bindkeyobject-key-args">#</a> [Ⓢ](https://github.com/lodash/lo | ||
dash/blob/3.0.0/lodash.src.js#L6851 "View in source") [Ⓣ][1] | ||
Creates a function that invokes the method at `object[key]` and prepends | Creates a function that invokes the method at `object[key]` and prepends | |
any additional `_.bindKey` arguments to those provided to the bound function. | any additional `_.bindKey` arguments to those provided to the bound function. | |
<br> | ||
<br> | ||
This method differs from `_.bind` by allowing bound functions to reference | This method differs from `_.bind` by allowing bound functions to reference | |
methods that may be redefined or don't yet exist. | methods that may be redefined or don't yet exist. | |
See [Peter Michaux's article](http://michaux.ca/articles/lazy-function-definitio n-pattern) | See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-def inition-pattern) | |
for more details. | for more details. | |
<br> | ||
<br> | ||
The `_.bindKey.placeholder` value, which defaults to `_` in monolithic | The `_.bindKey.placeholder` value, which defaults to `_` in monolithic | |
builds, may be used as a placeholder for partially applied arguments. | builds, may be used as a placeholder for partially applied arguments. | |
#### Arguments | #### Arguments | |
1. `object` *(Object)*: The object the method belongs to. | 1. `object` *(Object)*: The object to invoke the method on. | |
2. `key` *(string)*: The key of the method. | 2. `key` *(string)*: The key of the method. | |
3. `[args]` *(...*)*: The arguments to be partially applied. | 3. `[partials]` *(...*)*: The arguments to be partially applied. | |
#### Returns | #### Returns | |
*(Function)*: Returns the new bound function. | *(Function)*: Returns the new bound function. | |
#### Example | #### Example | |
```js | ```js | |
var object = { | var object = { | |
'user': 'fred', | 'user': 'fred', | |
'greet': function(greeting, punctuation) { | 'greet': function(greeting, punctuation) { | |
return greeting + ' ' + this.user + punctuation; | return greeting + ' ' + this.user + punctuation; | |
skipping to change at line 3037 | skipping to change at line 3180 | |
var bound = _.bindKey(object, 'greet', _, '!'); | var bound = _.bindKey(object, 'greet', _, '!'); | |
bound('hi'); | bound('hi'); | |
// => 'hiya fred!' | // => 'hiya fred!' | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_curryfunc"></a>`_.curry(func)` | ### <a id="_curryfunc-arityfunclength"></a>`_.curry(func, [arity=func.length])` | |
<a href="#_curryfunc">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.0 | <a href="#_curryfunc-arityfunclength">#</a> [Ⓢ](https://github.com/lodash | |
.0/lodash.src.js#L6902 "View in source") [Ⓣ][1] | /lodash/blob/4.0.0/lodash.js#L8319 "View in source") [Ⓣ][1] [Ⓝ](ht | |
tps://www.npmjs.com/package/lodash.curry "See the npm package") | ||
Creates a function that accepts one or more arguments of `func` that when | ||
called either invokes `func` returning its result, if all `func` arguments | ||
have been provided, or returns a function that accepts one or more of the | ||
remaining `func` arguments, and so on. The arity of `func` may be specified | ||
if `func.length` is not sufficient. | ||
Creates a function that accepts arguments of `func` and either invokes | ||
`func` returning its result, if at least `arity` number of arguments have | ||
been provided, or returns a function that accepts the remaining `func` | ||
arguments, and so on. The arity of `func` may be specified if `func.length` | ||
is not sufficient. | ||
<br> | ||
<br> | ||
The `_.curry.placeholder` value, which defaults to `_` in monolithic builds, | The `_.curry.placeholder` value, which defaults to `_` in monolithic builds, | |
may be used as a placeholder for provided arguments. | may be used as a placeholder for provided arguments. | |
*Note:** This method does not set the `length` property of curried functions. | <br> | |
<br> | ||
**Note:** This method doesn't set the "length" property of curried functions. | ||
#### Arguments | #### Arguments | |
1. `func` *(Function)*: The function to curry. | 1. `func` *(Function)*: The function to curry. | |
2. `[arity=func.length]` *(number)*: The arity of `func`. | 2. `[arity=func.length]` *(number)*: The arity of `func`. | |
#### Returns | #### Returns | |
*(Function)*: Returns the new curried function. | *(Function)*: Returns the new curried function. | |
#### Example | #### Example | |
```js | ```js | |
skipping to change at line 3084 | skipping to change at line 3230 | |
// using placeholders | // using placeholders | |
curried(1)(_, 3)(2); | curried(1)(_, 3)(2); | |
// => [1, 2, 3] | // => [1, 2, 3] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_curryrightfunc"></a>`_.curryRight(func)` | ### <a id="_curryrightfunc-arityfunclength"></a>`_.curryRight(func, [arity=func. | |
<a href="#_curryrightfunc">#</a> [Ⓢ](https://github.com/lodash/lodash/blo | length])` | |
b/3.0.0/lodash.src.js#L6948 "View in source") [Ⓣ][1] | <a href="#_curryrightfunc-arityfunclength">#</a> [Ⓢ](https://github.com/l | |
odash/lodash/blob/4.0.0/lodash.js#L8363 "View in source") [Ⓣ][1] [Ⓝ | ||
;](https://www.npmjs.com/package/lodash.curryright "See the npm package") | ||
This method is like `_.curry` except that arguments are applied to `func` | This method is like `_.curry` except that arguments are applied to `func` | |
in the manner of `_.partialRight` instead of `_.partial`. | in the manner of `_.partialRight` instead of `_.partial`. | |
<br> | ||
<br> | ||
The `_.curryRight.placeholder` value, which defaults to `_` in monolithic | The `_.curryRight.placeholder` value, which defaults to `_` in monolithic | |
builds, may be used as a placeholder for provided arguments. | builds, may be used as a placeholder for provided arguments. | |
*Note:** This method does not set the `length` property of curried functions. | <br> | |
<br> | ||
**Note:** This method doesn't set the "length" property of curried functions. | ||
#### Arguments | #### Arguments | |
1. `func` *(Function)*: The function to curry. | 1. `func` *(Function)*: The function to curry. | |
2. `[arity=func.length]` *(number)*: The arity of `func`. | 2. `[arity=func.length]` *(number)*: The arity of `func`. | |
#### Returns | #### Returns | |
*(Function)*: Returns the new curried function. | *(Function)*: Returns the new curried function. | |
#### Example | #### Example | |
```js | ```js | |
skipping to change at line 3128 | skipping to change at line 3277 | |
// using placeholders | // using placeholders | |
curried(3)(1, _)(2); | curried(3)(1, _)(2); | |
// => [1, 2, 3] | // => [1, 2, 3] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_debouncefunc-wait-options-optionsleadingfalse-optionsmaxwait-options | ### <a id="_debouncefunc-wait0-options"></a>`_.debounce(func, [wait=0], [options | |
trailingtrue"></a>`_.debounce(func, wait, [options], [options.leading=false], [o | ])` | |
ptions.maxWait], [options.trailing=true])` | <a href="#_debouncefunc-wait0-options">#</a> [Ⓢ](https://github.com/lodas | |
<a href="#_debouncefunc-wait-options-optionsleadingfalse-optionsmaxwait-optionst | h/lodash/blob/4.0.0/lodash.js#L8419 "View in source") [Ⓣ][1] [Ⓝ](h | |
railingtrue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.0.0/lodash | ttps://www.npmjs.com/package/lodash.debounce "See the npm package") | |
.src.js#L7019 "View in source") [Ⓣ][1] | ||
Creates a function that delays invoking `func` until after `wait` milliseconds | Creates a debounced function that delays invoking `func` until after `wait` | |
have elapsed since the last time it was invoked. The created function comes | milliseconds have elapsed since the last time the debounced function was | |
with a `cancel` method to cancel delayed invocations. Provide an options | invoked. The debounced function comes with a `cancel` method to cancel | |
object to indicate that `func` should be invoked on the leading and/or | delayed `func` invocations and a `flush` method to immediately invoke them. | |
trailing edge of the `wait` timeout. Subsequent calls to the debounced | Provide an options object to indicate whether `func` should be invoked on | |
function return the result of the last `func` invocation. | the leading and/or trailing edge of the `wait` timeout. The `func` is invoked | |
*Note:** If `leading` and `trailing` options are `true`, `func` is invoked | with the last arguments provided to the debounced function. Subsequent calls | |
to the debounced function return the result of the last `func` invocation. | ||
<br> | ||
<br> | ||
**Note:** If `leading` and `trailing` options are `true`, `func` is invoked | ||
on the trailing edge of the timeout only if the the debounced function is | on the trailing edge of the timeout only if the the debounced function is | |
invoked more than once during the `wait` timeout. | invoked more than once during the `wait` timeout. | |
<br> | ||
<br> | ||
See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-thro ttle-visual-explanation) | See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-thro ttle-visual-explanation) | |
for details over the differences between `_.debounce` and `_.throttle`. | for details over the differences between `_.debounce` and `_.throttle`. | |
#### Arguments | #### Arguments | |
1. `func` *(Function)*: The function to debounce. | 1. `func` *(Function)*: The function to debounce. | |
2. `wait` *(number)*: The number of milliseconds to delay. | 2. `[wait=0]` *(number)*: The number of milliseconds to delay. | |
3. `[options]` *(Object)*: The options object. | 3. `[options]` *(Object)*: The options object. | |
4. `[options.leading=false]` *(boolean)*: Specify invoking on the leading edge o f the timeout. | 4. `[options.leading=false]` *(boolean)*: Specify invoking on the leading edge o f the timeout. | |
5. `[options.maxWait]` *(number)*: The maximum time `func` is allowed to be dela yed before it is invoked. | 5. `[options.maxWait]` *(number)*: The maximum time `func` is allowed to be dela yed before it's invoked. | |
6. `[options.trailing=true]` *(boolean)*: Specify invoking on the trailing edge of the timeout. | 6. `[options.trailing=true]` *(boolean)*: Specify invoking on the trailing edge of the timeout. | |
#### Returns | #### Returns | |
*(Function)*: Returns the new debounced function. | *(Function)*: Returns the new debounced function. | |
#### Example | #### Example | |
```js | ```js | |
// avoid costly calculations while the window size is in flux | // avoid costly calculations while the window size is in flux | |
jQuery(window).on('resize', _.debounce(calculateLayout, 150)); | jQuery(window).on('resize', _.debounce(calculateLayout, 150)); | |
// invoke `sendMail` when the click event is fired, debouncing subsequent calls | // invoke `sendMail` when clicked, debouncing subsequent calls | |
jQuery('#postbox').on('click', _.debounce(sendMail, 300, { | jQuery(element).on('click', _.debounce(sendMail, 300, { | |
'leading': true, | 'leading': true, | |
'trailing': false | 'trailing': false | |
})); | })); | |
// ensure `batchLog` is invoked once after 1 second of debounced calls | // ensure `batchLog` is invoked once after 1 second of debounced calls | |
var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 }); | ||
var source = new EventSource('/stream'); | var source = new EventSource('/stream'); | |
jQuery(source).on('message', _.debounce(batchLog, 250, { | jQuery(source).on('message', debounced); | |
'maxWait': 1000 | ||
})); | ||
// cancel a debounced call | ||
var todoChanges = _.debounce(batchLog, 1000); | ||
Object.observe(models.todo, todoChanges); | ||
Object.observe(models, function(changes) { | ||
if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) { | ||
todoChanges.cancel(); | ||
} | ||
}, ['delete']); | ||
// ...at some point `models.todo` is changed | ||
models.todo.completed = true; | ||
// ...before 1 second has passed `models.todo` is deleted | // cancel a trailing debounced invocation | |
// which cancels the debounced `todoChanges` call | jQuery(window).on('popstate', debounced.cancel); | |
delete models.todo; | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_deferfunc-args"></a>`_.defer(func, [args])` | ### <a id="_deferfunc-args"></a>`_.defer(func, [args])` | |
<a href="#_deferfunc-args">#</a> [Ⓢ](https://github.com/lodash/lodash/blo b/3.0.0/lodash.src.js#L7148 "View in source") [Ⓣ][1] | <a href="#_deferfunc-args">#</a> [Ⓢ](https://github.com/lodash/lodash/blo b/4.0.0/lodash.js#L8551 "View in source") [Ⓣ][1] [Ⓝ](https://www.n pmjs.com/package/lodash.defer "See the npm package") | |
Defers invoking the `func` until the current call stack has cleared. Any | Defers invoking the `func` until the current call stack has cleared. Any | |
additional arguments are provided to `func` when it is invoked. | additional arguments are provided to `func` when it's invoked. | |
#### Arguments | #### Arguments | |
1. `func` *(Function)*: The function to defer. | 1. `func` *(Function)*: The function to defer. | |
2. `[args]` *(...*)*: The arguments to invoke the function with. | 2. `[args]` *(...*)*: The arguments to invoke `func` with. | |
#### Returns | #### Returns | |
*(number)*: Returns the timer id. | *(number)*: Returns the timer id. | |
#### Example | #### Example | |
```js | ```js | |
_.defer(function(text) { console.log(text); }, 'deferred'); | _.defer(function(text) { | |
console.log(text); | ||
}, 'deferred'); | ||
// logs 'deferred' after one or more milliseconds | // logs 'deferred' after one or more milliseconds | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_delayfunc-wait-args"></a>`_.delay(func, wait, [args])` | ### <a id="_delayfunc-wait-args"></a>`_.delay(func, wait, [args])` | |
<a href="#_delayfunc-wait-args">#</a> [Ⓢ](https://github.com/lodash/lodas h/blob/3.0.0/lodash.src.js#L7168 "View in source") [Ⓣ][1] | <a href="#_delayfunc-wait-args">#</a> [Ⓢ](https://github.com/lodash/lodas h/blob/4.0.0/lodash.js#L8573 "View in source") [Ⓣ][1] [Ⓝ](https:// www.npmjs.com/package/lodash.delay "See the npm package") | |
Invokes `func` after `wait` milliseconds. Any additional arguments are | Invokes `func` after `wait` milliseconds. Any additional arguments are | |
provided to `func` when it is invoked. | provided to `func` when it's invoked. | |
#### Arguments | #### Arguments | |
1. `func` *(Function)*: The function to delay. | 1. `func` *(Function)*: The function to delay. | |
2. `wait` *(number)*: The number of milliseconds to delay invocation. | 2. `wait` *(number)*: The number of milliseconds to delay invocation. | |
3. `[args]` *(...*)*: The arguments to invoke the function with. | 3. `[args]` *(...*)*: The arguments to invoke `func` with. | |
#### Returns | #### Returns | |
*(number)*: Returns the timer id. | *(number)*: Returns the timer id. | |
#### Example | #### Example | |
```js | ```js | |
_.delay(function(text) { console.log(text); }, 1000, 'later'); | _.delay(function(text) { | |
console.log(text); | ||
}, 1000, 'later'); | ||
// => logs 'later' after one second | // => logs 'later' after one second | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_flowfuncs"></a>`_.flow([funcs])` | ### <a id="_flipfunc"></a>`_.flip(func)` | |
<a href="#_flowfuncs">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.0 | <a href="#_flipfunc">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4.0. | |
.0/lodash.src.js#L7196 "View in source") [Ⓣ][1] | 0/lodash.js#L8594 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.c | |
om/package/lodash.flip "See the npm package") | ||
Creates a function that returns the result of invoking the provided | ||
functions with the `this` binding of the created function, where each | ||
successive invocation is supplied the return value of the previous. | ||
#### Arguments | ||
1. `[funcs]` *(...Function)*: Functions to invoke. | ||
#### Returns | ||
*(Function)*: Returns the new function. | ||
#### Example | ||
```js | ||
function add(x, y) { | ||
return x + y; | ||
} | ||
function square(n) { | ||
return n * n; | ||
} | ||
var addSquare = _.flow(add, square); | ||
addSquare(1, 2); | ||
// => 9 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_flowrightfuncs"></a>`_.flowRight([funcs])` | Creates a function that invokes `func` with arguments reversed. | |
<a href="#_flowrightfuncs">#</a> [Ⓢ](https://github.com/lodash/lodash/blo | ||
b/3.0.0/lodash.src.js#L7241 "View in source") [Ⓣ][1] | ||
This method is like `_.flow` except that it creates a function that | ||
invokes the provided functions from right to left. | ||
#### Arguments | #### Arguments | |
1. `[funcs]` *(...Function)*: Functions to invoke. | 1. `func` *(Function)*: The function to flip arguments for. | |
#### Returns | #### Returns | |
*(Function)*: Returns the new function. | *(Function)*: Returns the new function. | |
#### Example | #### Example | |
```js | ```js | |
function add(x, y) { | var flipped = _.flip(function() { | |
return x + y; | return _.toArray(arguments); | |
} | }); | |
function square(n) { | ||
return n * n; | ||
} | ||
var addSquare = _.flowRight(square, add); | flipped('a', 'b', 'c', 'd'); | |
addSquare(1, 2); | // => ['d', 'c', 'b', 'a'] | |
// => 9 | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_memoizefunc-resolver"></a>`_.memoize(func, [resolver])` | ### <a id="_memoizefunc-resolver"></a>`_.memoize(func, [resolver])` | |
<a href="#_memoizefunc-resolver">#</a> [Ⓢ](https://github.com/lodash/loda sh/blob/3.0.0/lodash.src.js#L7315 "View in source") [Ⓣ][1] | <a href="#_memoizefunc-resolver">#</a> [Ⓢ](https://github.com/lodash/loda sh/blob/4.0.0/lodash.js#L8640 "View in source") [Ⓣ][1] [Ⓝ](https:/ /www.npmjs.com/package/lodash.memoize "See the npm package") | |
Creates a function that memoizes the result of `func`. If `resolver` is | Creates a function that memoizes the result of `func`. If `resolver` is | |
provided it determines the cache key for storing the result based on the | provided it determines the cache key for storing the result based on the | |
arguments provided to the memoized function. By default, the first argument | arguments provided to the memoized function. By default, the first argument | |
provided to the memoized function is coerced to a string and used as the | provided to the memoized function is used as the map cache key. The `func` | |
cache key. The `func` is invoked with the `this` binding of the memoized | is invoked with the `this` binding of the memoized function. | |
function. | <br> | |
*Note:** The cache is exposed as the `cache` property on the memoized | <br> | |
**Note:** The cache is exposed as the `cache` property on the memoized | ||
function. Its creation may be customized by replacing the `_.memoize.Cache` | function. Its creation may be customized by replacing the `_.memoize.Cache` | |
constructor with one whose instances implement the ES `Map` method interface | constructor with one whose instances implement the [`Map`](http://ecma-internati | |
of `get`, `has`, and `set`. See the | onal.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object) | |
[ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-properties-o | method interface of `delete`, `get`, `has`, and `set`. | |
f-the-map-prototype-object) | ||
for more details. | ||
#### Arguments | #### Arguments | |
1. `func` *(Function)*: The function to have its output memoized. | 1. `func` *(Function)*: The function to have its output memoized. | |
2. `[resolver]` *(Function)*: The function to resolve the cache key. | 2. `[resolver]` *(Function)*: The function to resolve the cache key. | |
#### Returns | #### Returns | |
*(Function)*: Returns the new memoizing function. | *(Function)*: Returns the new memoizing function. | |
#### Example | #### Example | |
```js | ```js | |
var upperCase = _.memoize(function(string) { | var object = { 'a': 1, 'b': 2 }; | |
return string.toUpperCase(); | var other = { 'c': 3, 'd': 4 }; | |
}); | ||
upperCase('fred'); | var values = _.memoize(_.values); | |
// => 'FRED' | values(object); | |
// => [1, 2] | ||
// modifying the result cache | values(other); | |
upperCase.cache.set('fred, 'BARNEY'); | // => [3, 4] | |
upperCase('fred'); | ||
// => 'BARNEY' | ||
// replacing `_.memoize.Cache` | object.a = 2; | |
var object = { 'user': 'fred' }; | values(object); | |
var other = { 'user': 'barney' }; | // => [1, 2] | |
var identity = _.memoize(_.identity); | ||
identity(object); | // modifying the result cache | |
// => { 'user': 'fred' } | values.cache.set(object, ['a', 'b']); | |
identity(other); | values(object); | |
// => { 'user': 'fred' } | // => ['a', 'b'] | |
// replacing `_.memoize.Cache` | ||
_.memoize.Cache = WeakMap; | _.memoize.Cache = WeakMap; | |
var identity = _.memoize(_.identity); | ||
identity(object); | ||
// => { 'user': 'fred' } | ||
identity(other); | ||
// => { 'user': 'barney' } | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_negatepredicate"></a>`_.negate(predicate)` | ### <a id="_negatepredicate"></a>`_.negate(predicate)` | |
<a href="#_negatepredicate">#</a> [Ⓢ](https://github.com/lodash/lodash/bl ob/3.0.0/lodash.src.js#L7353 "View in source") [Ⓣ][1] | <a href="#_negatepredicate">#</a> [Ⓢ](https://github.com/lodash/lodash/bl ob/4.0.0/lodash.js#L8679 "View in source") [Ⓣ][1] [Ⓝ](https://www. npmjs.com/package/lodash.negate "See the npm package") | |
Creates a function that negates the result of the predicate `func`. The | Creates a function that negates the result of the predicate `func`. The | |
`func` predicate is invoked with the `this` binding and arguments of the | `func` predicate is invoked with the `this` binding and arguments of the | |
created function. | created function. | |
#### Arguments | #### Arguments | |
1. `predicate` *(Function)*: The predicate to negate. | 1. `predicate` *(Function)*: The predicate to negate. | |
#### Returns | #### Returns | |
*(Function)*: Returns the new function. | *(Function)*: Returns the new function. | |
skipping to change at line 3399 | skipping to change at line 3494 | |
_.filter([1, 2, 3, 4, 5, 6], _.negate(isEven)); | _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven)); | |
// => [1, 3, 5] | // => [1, 3, 5] | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_oncefunc"></a>`_.once(func)` | ### <a id="_oncefunc"></a>`_.once(func)` | |
<a href="#_oncefunc">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.0. 0/lodash.src.js#L7380 "View in source") [Ⓣ][1] | <a href="#_oncefunc">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4.0. 0/lodash.js#L8705 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.c om/package/lodash.once "See the npm package") | |
Creates a function that is restricted to invoking `func` once. Repeat calls | Creates a function that is restricted to invoking `func` once. Repeat calls | |
to the function return the value of the first call. The `func` is invoked | to the function return the value of the first invocation. The `func` is | |
with the `this` binding of the created function. | invoked with the `this` binding and arguments of the created function. | |
#### Arguments | #### Arguments | |
1. `func` *(Function)*: The function to restrict. | 1. `func` *(Function)*: The function to restrict. | |
#### Returns | #### Returns | |
*(Function)*: Returns the new restricted function. | *(Function)*: Returns the new restricted function. | |
#### Example | #### Example | |
```js | ```js | |
var initialize = _.once(createApplication); | var initialize = _.once(createApplication); | |
initialize(); | initialize(); | |
initialize(); | initialize(); | |
// `initialize` invokes `createApplication` once | // `initialize` invokes `createApplication` once | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_partialfunc-args"></a>`_.partial(func, [args])` | ### <a id="_overargsfunc-transforms"></a>`_.overArgs(func, [transforms])` | |
<a href="#_partialfunc-args">#</a> [Ⓢ](https://github.com/lodash/lodash/b | <a href="#_overargsfunc-transforms">#</a> [Ⓢ](https://github.com/lodash/l | |
lob/3.0.0/lodash.src.js#L7416 "View in source") [Ⓣ][1] | odash/blob/4.0.0/lodash.js#L8740 "View in source") [Ⓣ][1] [Ⓝ](http | |
s://www.npmjs.com/package/lodash.overargs "See the npm package") | ||
Creates a function that invokes `func` with arguments transformed by | ||
corresponding `transforms`. | ||
#### Arguments | ||
1. `func` *(Function)*: The function to wrap. | ||
2. `[transforms]` *(...(Function|Function[])*: The functions to transfor | ||
m arguments, specified individually or in arrays. | ||
#### Returns | ||
*(Function)*: Returns the new function. | ||
#### Example | ||
```js | ||
function doubled(n) { | ||
return n * 2; | ||
} | ||
function square(n) { | ||
return n * n; | ||
} | ||
var func = _.overArgs(function(x, y) { | ||
return [x, y]; | ||
}, square, doubled); | ||
func(9, 3); | ||
// => [81, 6] | ||
func(10, 5); | ||
// => [100, 10] | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_partialfunc-partials"></a>`_.partial(func, [partials])` | ||
<a href="#_partialfunc-partials">#</a> [Ⓢ](https://github.com/lodash/loda | ||
sh/blob/4.0.0/lodash.js#L8787 "View in source") [Ⓣ][1] [Ⓝ](https:/ | ||
/www.npmjs.com/package/lodash.partial "See the npm package") | ||
Creates a function that invokes `func` with `partial` arguments prepended | Creates a function that invokes `func` with `partial` arguments prepended | |
to those provided to the new function. This method is like `_.bind` except | to those provided to the new function. This method is like `_.bind` except | |
it does **not** alter the `this` binding. | it does **not** alter the `this` binding. | |
<br> | ||
<br> | ||
The `_.partial.placeholder` value, which defaults to `_` in monolithic | The `_.partial.placeholder` value, which defaults to `_` in monolithic | |
builds, may be used as a placeholder for partially applied arguments. | builds, may be used as a placeholder for partially applied arguments. | |
*Note:** This method does not set the `length` property of partially | <br> | |
<br> | ||
**Note:** This method doesn't set the "length" property of partially | ||
applied functions. | applied functions. | |
#### Arguments | #### Arguments | |
1. `func` *(Function)*: The function to partially apply arguments to. | 1. `func` *(Function)*: The function to partially apply arguments to. | |
2. `[args]` *(...*)*: The arguments to be partially applied. | 2. `[partials]` *(...*)*: The arguments to be partially applied. | |
#### Returns | #### Returns | |
*(Function)*: Returns the new partially applied function. | *(Function)*: Returns the new partially applied function. | |
#### Example | #### Example | |
```js | ```js | |
var greet = function(greeting, name) { | var greet = function(greeting, name) { | |
return greeting + ' ' + name; | return greeting + ' ' + name; | |
}; | }; | |
skipping to change at line 3464 | skipping to change at line 3601 | |
var greetFred = _.partial(greet, _, 'fred'); | var greetFred = _.partial(greet, _, 'fred'); | |
greetFred('hi'); | greetFred('hi'); | |
// => 'hi fred' | // => 'hi fred' | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_partialrightfunc-args"></a>`_.partialRight(func, [args])` | ### <a id="_partialrightfunc-partials"></a>`_.partialRight(func, [partials])` | |
<a href="#_partialrightfunc-args">#</a> [Ⓢ](https://github.com/lodash/lod | <a href="#_partialrightfunc-partials">#</a> [Ⓢ](https://github.com/lodash | |
ash/blob/3.0.0/lodash.src.js#L7454 "View in source") [Ⓣ][1] | /lodash/blob/4.0.0/lodash.js#L8823 "View in source") [Ⓣ][1] [Ⓝ](ht | |
tps://www.npmjs.com/package/lodash.partialright "See the npm package") | ||
This method is like `_.partial` except that partially applied arguments | This method is like `_.partial` except that partially applied arguments | |
are appended to those provided to the new function. | are appended to those provided to the new function. | |
<br> | ||
<br> | ||
The `_.partialRight.placeholder` value, which defaults to `_` in monolithic | The `_.partialRight.placeholder` value, which defaults to `_` in monolithic | |
builds, may be used as a placeholder for partially applied arguments. | builds, may be used as a placeholder for partially applied arguments. | |
*Note:** This method does not set the `length` property of partially | <br> | |
<br> | ||
**Note:** This method doesn't set the "length" property of partially | ||
applied functions. | applied functions. | |
#### Arguments | #### Arguments | |
1. `func` *(Function)*: The function to partially apply arguments to. | 1. `func` *(Function)*: The function to partially apply arguments to. | |
2. `[args]` *(...*)*: The arguments to be partially applied. | 2. `[partials]` *(...*)*: The arguments to be partially applied. | |
#### Returns | #### Returns | |
*(Function)*: Returns the new partially applied function. | *(Function)*: Returns the new partially applied function. | |
#### Example | #### Example | |
```js | ```js | |
var greet = function(greeting, name) { | var greet = function(greeting, name) { | |
return greeting + ' ' + name; | return greeting + ' ' + name; | |
}; | }; | |
skipping to change at line 3504 | skipping to change at line 3644 | |
sayHelloTo('fred'); | sayHelloTo('fred'); | |
// => 'hello fred' | // => 'hello fred' | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_reargfunc-indexes"></a>`_.rearg(func, indexes)` | ### <a id="_reargfunc-indexes"></a>`_.rearg(func, indexes)` | |
<a href="#_reargfunc-indexes">#</a> [Ⓢ](https://github.com/lodash/lodash/ blob/3.0.0/lodash.src.js#L7487 "View in source") [Ⓣ][1] | <a href="#_reargfunc-indexes">#</a> [Ⓢ](https://github.com/lodash/lodash/ blob/4.0.0/lodash.js#L8850 "View in source") [Ⓣ][1] [Ⓝ](https://ww w.npmjs.com/package/lodash.rearg "See the npm package") | |
Creates a function that invokes `func` with arguments arranged according | Creates a function that invokes `func` with arguments arranged according | |
to the specified indexes where the argument value at the first index is | to the specified indexes where the argument value at the first index is | |
provided as the first argument, the argument value at the second index is | provided as the first argument, the argument value at the second index is | |
provided as the second argument, and so on. | provided as the second argument, and so on. | |
#### Arguments | #### Arguments | |
1. `func` *(Function)*: The function to rearrange arguments for. | 1. `func` *(Function)*: The function to rearrange arguments for. | |
2. `indexes` *(...(number|number[])*: The arranged argument indexes, spe cified as individual indexes or arrays of indexes. | 2. `indexes` *(...(number|number[])*: The arranged argument indexes, spe cified individually or in arrays. | |
#### Returns | #### Returns | |
*(Function)*: Returns the new function. | *(Function)*: Returns the new function. | |
#### Example | #### Example | |
```js | ```js | |
var rearged = _.rearg(function(a, b, c) { | var rearged = _.rearg(function(a, b, c) { | |
return [a, b, c]; | return [a, b, c]; | |
}, 2, 0, 1); | }, 2, 0, 1); | |
rearged('b', 'c', 'a') | rearged('b', 'c', 'a') | |
// => ['a', 'b', 'c'] | // => ['a', 'b', 'c'] | |
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_restfunc-startfunclength-1"></a>`_.rest(func, [start=func.length-1]) | ||
` | ||
<a href="#_restfunc-startfunclength-1">#</a> [Ⓢ](https://github.com/lodas | ||
h/lodash/blob/4.0.0/lodash.js#L8876 "View in source") [Ⓣ][1] [Ⓝ](h | ||
ttps://www.npmjs.com/package/lodash.rest "See the npm package") | ||
Creates a function that invokes `func` with the `this` binding of the | ||
created function and arguments from `start` and beyond provided as an array. | ||
<br> | ||
<br> | ||
**Note:** This method is based on the [rest parameter](https://mdn.io/rest_param | ||
eters). | ||
#### Arguments | ||
1. `func` *(Function)*: The function to apply a rest parameter to. | ||
2. `[start=func.length-1]` *(number)*: The start position of the rest parameter. | ||
#### Returns | ||
*(Function)*: Returns the new function. | ||
#### Example | ||
```js | ||
var say = _.rest(function(what, names) { | ||
return what + ' ' + _.initial(names).join(', ') + | ||
(_.size(names) > 1 ? ', & ' : '') + _.last(names); | ||
}); | ||
var map = _.rearg(_.map, [1, 0]); | say('hello', 'fred', 'barney', 'pebbles'); | |
map(function(n) { return n * 3; }, [1, 2, 3]); | // => 'hello fred, barney, & pebbles' | |
// => [3, 6, 9] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_throttlefunc-wait-options-optionsleadingtrue-optionstrailingtrue"></ | ### <a id="_spreadfunc"></a>`_.spread(func)` | |
a>`_.throttle(func, wait, [options], [options.leading=true], [options.trailing=t | <a href="#_spreadfunc">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4. | |
rue])` | 0.0/lodash.js#L8936 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs | |
<a href="#_throttlefunc-wait-options-optionsleadingtrue-optionstrailingtrue">#</ | .com/package/lodash.spread "See the npm package") | |
a> [Ⓢ](https://github.com/lodash/lodash/blob/3.0.0/lodash.src.js#L7530 "V | ||
iew in source") [Ⓣ][1] | Creates a function that invokes `func` with the `this` binding of the created | |
function and an array of arguments much like [`Function#apply`](https://es5.gith | ||
ub.io/#x15.3.4.3). | ||
<br> | ||
<br> | ||
**Note:** This method is based on the [spread operator](https://mdn.io/spread_op | ||
erator). | ||
#### Arguments | ||
1. `func` *(Function)*: The function to spread arguments over. | ||
#### Returns | ||
*(Function)*: Returns the new function. | ||
#### Example | ||
```js | ||
var say = _.spread(function(who, what) { | ||
return who + ' says ' + what; | ||
}); | ||
say(['fred', 'hello']); | ||
// => 'fred says hello' | ||
// with a Promise | ||
var numbers = Promise.all([ | ||
Promise.resolve(40), | ||
Promise.resolve(36) | ||
]); | ||
Creates a function that only invokes `func` at most once per every `wait` | numbers.then(_.spread(function(x, y) { | |
milliseconds. The created function comes with a `cancel` method to cancel | return x + y; | |
delayed invocations. Provide an options object to indicate that `func` | })); | |
should be invoked on the leading and/or trailing edge of the `wait` timeout. | // => a Promise of 76 | |
Subsequent calls to the throttled function return the result of the last | ``` | |
`func` call. | * * * | |
*Note:** If `leading` and `trailing` options are `true`, `func` is invoked | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_throttlefunc-wait0-options"></a>`_.throttle(func, [wait=0], [options | ||
])` | ||
<a href="#_throttlefunc-wait0-options">#</a> [Ⓢ](https://github.com/lodas | ||
h/lodash/blob/4.0.0/lodash.js#L8985 "View in source") [Ⓣ][1] [Ⓝ](h | ||
ttps://www.npmjs.com/package/lodash.throttle "See the npm package") | ||
Creates a throttled function that only invokes `func` at most once per | ||
every `wait` milliseconds. The throttled function comes with a `cancel` | ||
method to cancel delayed `func` invocations and a `flush` method to | ||
immediately invoke them. Provide an options object to indicate whether | ||
`func` should be invoked on the leading and/or trailing edge of the `wait` | ||
timeout. The `func` is invoked with the last arguments provided to the | ||
throttled function. Subsequent calls to the throttled function return the | ||
result of the last `func` invocation. | ||
<br> | ||
<br> | ||
**Note:** If `leading` and `trailing` options are `true`, `func` is invoked | ||
on the trailing edge of the timeout only if the the throttled function is | on the trailing edge of the timeout only if the the throttled function is | |
invoked more than once during the `wait` timeout. | invoked more than once during the `wait` timeout. | |
<br> | ||
<br> | ||
See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-thro ttle-visual-explanation) | See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-thro ttle-visual-explanation) | |
for details over the differences between `_.throttle` and `_.debounce`. | for details over the differences between `_.throttle` and `_.debounce`. | |
#### Arguments | #### Arguments | |
1. `func` *(Function)*: The function to throttle. | 1. `func` *(Function)*: The function to throttle. | |
2. `wait` *(number)*: The number of milliseconds to throttle invocations to. | 2. `[wait=0]` *(number)*: The number of milliseconds to throttle invocations to. | |
3. `[options]` *(Object)*: The options object. | 3. `[options]` *(Object)*: The options object. | |
4. `[options.leading=true]` *(boolean)*: Specify invoking on the leading edge of the timeout. | 4. `[options.leading=true]` *(boolean)*: Specify invoking on the leading edge of the timeout. | |
5. `[options.trailing=true]` *(boolean)*: Specify invoking on the trailing edge of the timeout. | 5. `[options.trailing=true]` *(boolean)*: Specify invoking on the trailing edge of the timeout. | |
#### Returns | #### Returns | |
*(Function)*: Returns the new throttled function. | *(Function)*: Returns the new throttled function. | |
#### Example | #### Example | |
```js | ```js | |
// avoid excessively updating the position while scrolling | // avoid excessively updating the position while scrolling | |
jQuery(window).on('scroll', _.throttle(updatePosition, 100)); | jQuery(window).on('scroll', _.throttle(updatePosition, 100)); | |
// invoke `renewToken` when the click event is fired, but not more than once eve ry 5 minutes | // invoke `renewToken` when the click event is fired, but not more than once eve ry 5 minutes | |
var throttled = _.throttle(renewToken, 300000, { 'trailing': false }) | var throttled = _.throttle(renewToken, 300000, { 'trailing': false }); | |
jQuery('.interactive').on('click', throttled); | jQuery(element).on('click', throttled); | |
// cancel a trailing throttled call | // cancel a trailing throttled invocation | |
jQuery(window).on('popstate', throttled.cancel); | jQuery(window).on('popstate', throttled.cancel); | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_unaryfunc"></a>`_.unary(func)` | ||
<a href="#_unaryfunc">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4.0 | ||
.0/lodash.js#L9013 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs. | ||
com/package/lodash.unary "See the npm package") | ||
Creates a function that accepts up to one argument, ignoring any | ||
additional arguments. | ||
#### Arguments | ||
1. `func` *(Function)*: The function to cap arguments for. | ||
#### Returns | ||
*(Function)*: Returns the new function. | ||
#### Example | ||
```js | ||
_.map(['6', '8', '10'], _.unary(parseInt)); | ||
// => [6, 8, 10] | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_wrapvalue-wrapper"></a>`_.wrap(value, wrapper)` | ### <a id="_wrapvalue-wrapper"></a>`_.wrap(value, wrapper)` | |
<a href="#_wrapvalue-wrapper">#</a> [Ⓢ](https://github.com/lodash/lodash/ blob/3.0.0/lodash.src.js#L7570 "View in source") [Ⓣ][1] | <a href="#_wrapvalue-wrapper">#</a> [Ⓢ](https://github.com/lodash/lodash/ blob/4.0.0/lodash.js#L9038 "View in source") [Ⓣ][1] [Ⓝ](https://ww w.npmjs.com/package/lodash.wrap "See the npm package") | |
Creates a function that provides `value` to the wrapper function as its | Creates a function that provides `value` to the wrapper function as its | |
first argument. Any additional arguments provided to the function are | first argument. Any additional arguments provided to the function are | |
appended to those provided to the wrapper function. The wrapper is invoked | appended to those provided to the wrapper function. The wrapper is invoked | |
with the `this` binding of the created function. | with the `this` binding of the created function. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to wrap. | 1. `value` *(*)*: The value to wrap. | |
2. `wrapper` *(Function)*: The wrapper function. | 2. `wrapper` *(Function)*: The wrapper function. | |
skipping to change at line 3617 | skipping to change at line 3854 | |
<!-- /div --> | <!-- /div --> | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
## `“Lang” Methods` | ## `“Lang” Methods` | |
<!-- div --> | <!-- div --> | |
### <a id="_clonevalue-isdeep-customizer-thisarg"></a>`_.clone(value, [isDeep], | ### <a id="_clonevalue"></a>`_.clone(value)` | |
[customizer], [thisArg])` | <a href="#_clonevalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4. | |
<a href="#_clonevalue-isdeep-customizer-thisarg">#</a> [Ⓢ](https://github | 0.0/lodash.js#L9069 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs | |
.com/lodash/lodash/blob/3.0.0/lodash.src.js#L7626 "View in source") [Ⓣ][1 | .com/package/lodash.clone "See the npm package") | |
] | ||
Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned, | Creates a shallow clone of `value`. | |
otherwise they are assigned by reference. If `customizer` is provided it is | <br> | |
invoked to produce the cloned values. If `customizer` returns `undefined` | <br> | |
cloning is handled by the method instead. The `customizer` is bound to | **Note:** This method is loosely based on the | |
`thisArg` and invoked with two argument; (value [, index|key, object]). | [structured clone algorithm](https://mdn.io/Structured_clone_algorithm) | |
*Note:** This method is loosely based on the structured clone algorithm. | and supports cloning arrays, array buffers, booleans, date objects, maps, | |
The enumerable properties of `arguments` objects and objects created by | numbers, `Object` objects, regexes, sets, strings, symbols, and typed | |
constructors other than `Object` are cloned to plain `Object` objects. An | arrays. The own enumerable properties of `arguments` objects are cloned | |
empty object is returned for uncloneable values such as functions, DOM nodes, | as plain objects. An empty object is returned for uncloneable values such | |
Maps, Sets, and WeakMaps. See the [HTML5 specification](http://www.w3.org/TR/htm | as error objects, functions, DOM nodes, and WeakMaps. | |
l5/infrastructure.html#internal-structured-cloning-algorithm) | ||
for more details. | ||
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to clone. | 1. `value` *(*)*: The value to clone. | |
2. `[isDeep]` *(boolean)*: Specify a deep clone. | ||
3. `[customizer]` *(Function)*: The function to customize cloning values. | ||
4. `[thisArg]` *(*)*: The `this` binding of `customizer`. | ||
#### Returns | #### Returns | |
*(*)*: Returns the cloned value. | *(*)*: Returns the cloned value. | |
#### Example | #### Example | |
```js | ```js | |
var users = [ | var objects = [{ 'a': 1 }, { 'b': 2 }]; | |
{ 'user': 'barney' }, | ||
{ 'user': 'fred' } | ||
]; | ||
var shallow = _.clone(users); | var shallow = _.clone(objects); | |
shallow[0] === users[0]; | console.log(shallow[0] === objects[0]); | |
// => true | // => true | |
``` | ||
* * * | ||
var deep = _.clone(users, true); | <!-- /div --> | |
deep[0] === users[0]; | ||
<!-- div --> | ||
### <a id="_clonedeepvalue"></a>`_.cloneDeep(value)` | ||
<a href="#_clonedeepvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blo | ||
b/4.0.0/lodash.js#L9122 "View in source") [Ⓣ][1] [Ⓝ](https://www.n | ||
pmjs.com/package/lodash.clonedeep "See the npm package") | ||
This method is like `_.clone` except that it recursively clones `value`. | ||
#### Arguments | ||
1. `value` *(*)*: The value to recursively clone. | ||
#### Returns | ||
*(*)*: Returns the deep cloned value. | ||
#### Example | ||
```js | ||
var objects = [{ 'a': 1 }, { 'b': 2 }]; | ||
var deep = _.cloneDeep(objects); | ||
console.log(deep[0] === objects[0]); | ||
// => false | // => false | |
``` | ||
* * * | ||
// using a customizer callback | <!-- /div --> | |
var body = _.clone(document.body, function(value) { | ||
return _.isElement(value) ? value.cloneNode(false) : undefined; | <!-- div --> | |
}); | ||
### <a id="_clonedeepwithvalue-customizer"></a>`_.cloneDeepWith(value, [customiz | ||
er])` | ||
<a href="#_clonedeepwithvalue-customizer">#</a> [Ⓢ](https://github.com/lo | ||
dash/lodash/blob/4.0.0/lodash.js#L9152 "View in source") [Ⓣ][1] [Ⓝ | ||
](https://www.npmjs.com/package/lodash.clonedeepwith "See the npm package") | ||
This method is like `_.cloneWith` except that it recursively clones `value`. | ||
#### Arguments | ||
1. `value` *(*)*: The value to recursively clone. | ||
2. `[customizer]` *(Function)*: The function to customize cloning. | ||
#### Returns | ||
*(*)*: Returns the deep cloned value. | ||
#### Example | ||
```js | ||
function customizer(value) { | ||
if (_.isElement(value)) { | ||
return value.cloneNode(true); | ||
} | ||
} | ||
body === document.body | var el = _.cloneDeep(document.body, customizer); | |
console.log(el === document.body); | ||
// => false | // => false | |
body.nodeName | console.log(el.nodeName); | |
// => BODY | // => 'BODY' | |
body.childNodes.length; | console.log(el.childNodes.length); | |
// => 20 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_clonewithvalue-customizer"></a>`_.cloneWith(value, [customizer])` | ||
<a href="#_clonewithvalue-customizer">#</a> [Ⓢ](https://github.com/lodash | ||
/lodash/blob/4.0.0/lodash.js#L9102 "View in source") [Ⓣ][1] [Ⓝ](ht | ||
tps://www.npmjs.com/package/lodash.clonewith "See the npm package") | ||
This method is like `_.clone` except that it accepts `customizer` which | ||
is invoked to produce the cloned value. If `customizer` returns `undefined` | ||
cloning is handled by the method instead. The `customizer` is invoked with | ||
up to five arguments; (value [, index|key, object, stack]). | ||
#### Arguments | ||
1. `value` *(*)*: The value to clone. | ||
2. `[customizer]` *(Function)*: The function to customize cloning. | ||
#### Returns | ||
*(*)*: Returns the cloned value. | ||
#### Example | ||
```js | ||
function customizer(value) { | ||
if (_.isElement(value)) { | ||
return value.cloneNode(false); | ||
} | ||
} | ||
var el = _.clone(document.body, customizer); | ||
console.log(el === document.body); | ||
// => false | ||
console.log(el.nodeName); | ||
// => 'BODY' | ||
console.log(el.childNodes.length); | ||
// => 0 | // => 0 | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_clonedeepvalue-customizer-thisarg"></a>`_.cloneDeep(value, [customiz | ### <a id="_eqvalue-other"></a>`_.eq(value, other)` | |
er], [thisArg])` | <a href="#_eqvalue-other">#</a> [Ⓢ](https://github.com/lodash/lodash/blob | |
<a href="#_clonedeepvalue-customizer-thisarg">#</a> [Ⓢ](https://github.co | /4.0.0/lodash.js#L9186 "View in source") [Ⓣ][1] [Ⓝ](https://www.np | |
m/lodash/lodash/blob/3.0.0/lodash.src.js#L7680 "View in source") [Ⓣ][1] | mjs.com/package/lodash.eq "See the npm package") | |
Creates a deep clone of `value`. If `customizer` is provided it is invoked | Performs a [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-sam | |
to produce the cloned values. If `customizer` returns `undefined` cloning | evaluezero) | |
is handled by the method instead. The `customizer` is bound to `thisArg` | comparison between two values to determine if they are equivalent. | |
and invoked with two argument; (value [, index|key, object]). | ||
*Note:** This method is loosely based on the structured clone algorithm. | ||
The enumerable properties of `arguments` objects and objects created by | ||
constructors other than `Object` are cloned to plain `Object` objects. An | ||
empty object is returned for uncloneable values such as functions, DOM nodes, | ||
Maps, Sets, and WeakMaps. See the [HTML5 specification](http://www.w3.org/TR/htm | ||
l5/infrastructure.html#internal-structured-cloning-algorithm) | ||
for more details. | ||
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to deep clone. | 1. `value` *(*)*: The value to compare. | |
2. `[customizer]` *(Function)*: The function to customize cloning values. | 2. `other` *(*)*: The other value to compare. | |
3. `[thisArg]` *(*)*: The `this` binding of `customizer`. | ||
#### Returns | #### Returns | |
*(*)*: Returns the deep cloned value. | *(boolean)*: Returns `true` if the values are equivalent, else `false`. | |
#### Example | #### Example | |
```js | ```js | |
var users = [ | var object = { 'user': 'fred' }; | |
{ 'user': 'barney' }, | var other = { 'user': 'fred' }; | |
{ 'user': 'fred' } | ||
]; | _.eq(object, object); | |
// => true | ||
var deep = _.cloneDeep(users); | _.eq(object, other); | |
deep[0] === users[0]; | ||
// => false | // => false | |
// using a customizer callback | _.eq('a', 'a'); | |
var el = _.cloneDeep(document.body, function(value) { | // => true | |
return _.isElement(value) ? value.cloneNode(true) : undefined; | ||
}); | ||
body === document.body | _.eq('a', Object('a')); | |
// => false | ||
_.eq(NaN, NaN); | ||
// => true | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_gtvalue-other"></a>`_.gt(value, other)` | ||
<a href="#_gtvalue-other">#</a> [Ⓢ](https://github.com/lodash/lodash/blob | ||
/4.0.0/lodash.js#L9210 "View in source") [Ⓣ][1] [Ⓝ](https://www.np | ||
mjs.com/package/lodash.gt "See the npm package") | ||
Checks if `value` is greater than `other`. | ||
#### Arguments | ||
1. `value` *(*)*: The value to compare. | ||
2. `other` *(*)*: The other value to compare. | ||
#### Returns | ||
*(boolean)*: Returns `true` if `value` is greater than `other`, else `false`. | ||
#### Example | ||
```js | ||
_.gt(3, 1); | ||
// => true | ||
_.gt(3, 3); | ||
// => false | ||
_.gt(1, 3); | ||
// => false | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_gtevalue-other"></a>`_.gte(value, other)` | ||
<a href="#_gtevalue-other">#</a> [Ⓢ](https://github.com/lodash/lodash/blo | ||
b/4.0.0/lodash.js#L9234 "View in source") [Ⓣ][1] [Ⓝ](https://www.n | ||
pmjs.com/package/lodash.gte "See the npm package") | ||
Checks if `value` is greater than or equal to `other`. | ||
#### Arguments | ||
1. `value` *(*)*: The value to compare. | ||
2. `other` *(*)*: The other value to compare. | ||
#### Returns | ||
*(boolean)*: Returns `true` if `value` is greater than or equal to `other`, els | ||
e `false`. | ||
#### Example | ||
```js | ||
_.gte(3, 1); | ||
// => true | ||
_.gte(3, 3); | ||
// => true | ||
_.gte(1, 3); | ||
// => false | // => false | |
body.nodeName | ||
// => BODY | ||
body.childNodes.length; | ||
// => 20 | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_isargumentsvalue"></a>`_.isArguments(value)` | ### <a id="_isargumentsvalue"></a>`_.isArguments(value)` | |
<a href="#_isargumentsvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/b lob/3.0.0/lodash.src.js#L7701 "View in source") [Ⓣ][1] | <a href="#_isargumentsvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/b lob/4.0.0/lodash.js#L9254 "View in source") [Ⓣ][1] [Ⓝ](https://www .npmjs.com/package/lodash.isarguments "See the npm package") | |
Checks if `value` is classified as an `arguments` object. | Checks if `value` is likely an `arguments` object. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | *(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | |
#### Example | #### Example | |
```js | ```js | |
(function() { return _.isArguments(arguments); })(); | _.isArguments(function() { return arguments; }()); | |
// => true | // => true | |
_.isArguments([1, 2, 3]); | _.isArguments([1, 2, 3]); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_isarrayvalue"></a>`_.isArray(value)` | ### <a id="_isarrayvalue"></a>`_.isArray(value)` | |
<a href="#_isarrayvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 3.0.0/lodash.src.js#L7730 "View in source") [Ⓣ][1] | <a href="#_isarrayvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 4.0.0/lodash.js#L9283 "View in source") [Ⓣ][1] [Ⓝ](https://www.npm js.com/package/lodash.isarray "See the npm package") | |
Checks if `value` is classified as an `Array` object. | Checks if `value` is classified as an `Array` object. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | *(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | |
#### Example | #### Example | |
```js | ```js | |
_.isArray([1, 2, 3]); | _.isArray([1, 2, 3]); | |
// => true | // => true | |
(function() { return _.isArray(arguments); })(); | _.isArray(document.body.children); | |
// => false | ||
_.isArray('abc'); | ||
// => false | ||
_.isArray(_.noop); | ||
// => false | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_isarraylikevalue"></a>`_.isArrayLike(value)` | ||
<a href="#_isarraylikevalue">#</a> [Ⓢ](https://github.com/lodash/lodash/b | ||
lob/4.0.0/lodash.js#L9310 "View in source") [Ⓣ][1] [Ⓝ](https://www | ||
.npmjs.com/package/lodash.isarraylike "See the npm package") | ||
Checks if `value` is array-like. A value is considered array-like if it's | ||
not a function and has a `value.length` that's an integer greater than or | ||
equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. | ||
#### Arguments | ||
1. `value` *(*)*: The value to check. | ||
#### Returns | ||
*(boolean)*: Returns `true` if `value` is array-like, else `false`. | ||
#### Example | ||
```js | ||
_.isArrayLike([1, 2, 3]); | ||
// => true | ||
_.isArrayLike(document.body.children); | ||
// => true | ||
_.isArrayLike('abc'); | ||
// => true | ||
_.isArrayLike(_.noop); | ||
// => false | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_isarraylikeobjectvalue"></a>`_.isArrayLikeObject(value)` | ||
<a href="#_isarraylikeobjectvalue">#</a> [Ⓢ](https://github.com/lodash/lo | ||
dash/blob/4.0.0/lodash.js#L9339 "View in source") [Ⓣ][1] [Ⓝ](https | ||
://www.npmjs.com/package/lodash.isarraylikeobject "See the npm package") | ||
This method is like `_.isArrayLike` except that it also checks if `value` | ||
is an object. | ||
#### Arguments | ||
1. `value` *(*)*: The value to check. | ||
#### Returns | ||
*(boolean)*: Returns `true` if `value` is an array-like object, else `false`. | ||
#### Example | ||
```js | ||
_.isArrayLikeObject([1, 2, 3]); | ||
// => true | ||
_.isArrayLikeObject(document.body.children); | ||
// => true | ||
_.isArrayLikeObject('abc'); | ||
// => false | ||
_.isArrayLikeObject(_.noop); | ||
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_isbooleanvalue"></a>`_.isBoolean(value)` | ### <a id="_isbooleanvalue"></a>`_.isBoolean(value)` | |
<a href="#_isbooleanvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blo b/3.0.0/lodash.src.js#L7750 "View in source") [Ⓣ][1] | <a href="#_isbooleanvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blo b/4.0.0/lodash.js#L9359 "View in source") [Ⓣ][1] [Ⓝ](https://www.n pmjs.com/package/lodash.isboolean "See the npm package") | |
Checks if `value` is classified as a boolean primitive or object. | Checks if `value` is classified as a boolean primitive or object. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | *(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | |
#### Example | #### Example | |
skipping to change at line 3801 | skipping to change at line 4230 | |
_.isBoolean(null); | _.isBoolean(null); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_isdatevalue"></a>`_.isDate(value)` | ### <a id="_isdatevalue"></a>`_.isDate(value)` | |
<a href="#_isdatevalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3 .0.0/lodash.src.js#L7770 "View in source") [Ⓣ][1] | <a href="#_isdatevalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4 .0.0/lodash.js#L9380 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmj s.com/package/lodash.isdate "See the npm package") | |
Checks if `value` is classified as a `Date` object. | Checks if `value` is classified as a `Date` object. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | *(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | |
#### Example | #### Example | |
skipping to change at line 3826 | skipping to change at line 4255 | |
_.isDate('Mon April 23 2012'); | _.isDate('Mon April 23 2012'); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_iselementvalue"></a>`_.isElement(value)` | ### <a id="_iselementvalue"></a>`_.isElement(value)` | |
<a href="#_iselementvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blo b/3.0.0/lodash.src.js#L7790 "View in source") [Ⓣ][1] | <a href="#_iselementvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blo b/4.0.0/lodash.js#L9400 "View in source") [Ⓣ][1] [Ⓝ](https://www.n pmjs.com/package/lodash.iselement "See the npm package") | |
Checks if `value` is a DOM element. | Checks if `value` is likely a DOM element. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is a DOM element, else `false`. | *(boolean)*: Returns `true` if `value` is a DOM element, else `false`. | |
#### Example | #### Example | |
```js | ```js | |
_.isElement(document.body); | _.isElement(document.body); | |
skipping to change at line 3851 | skipping to change at line 4280 | |
_.isElement('<body>'); | _.isElement('<body>'); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_isemptyvalue"></a>`_.isEmpty(value)` | ### <a id="_isemptyvalue"></a>`_.isEmpty(value)` | |
<a href="#_isemptyvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 3.0.0/lodash.src.js#L7828 "View in source") [Ⓣ][1] | <a href="#_isemptyvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 4.0.0/lodash.js#L9431 "View in source") [Ⓣ][1] [Ⓝ](https://www.npm js.com/package/lodash.isempty "See the npm package") | |
Checks if a value is empty. A value is considered empty unless it is an | Checks if `value` is empty. A value is considered empty unless it's an | |
`arguments` object, array, string, or jQuery-like collection with a length | `arguments` object, array, string, or jQuery-like collection with a length | |
greater than `0` or an object with own enumerable properties. | greater than `0` or an object with own enumerable properties. | |
#### Arguments | #### Arguments | |
1. `value` *(Array|Object|string)*: The value to inspect. | 1. `value` *(Array|Object|string)*: The value to inspect. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is empty, else `false`. | *(boolean)*: Returns `true` if `value` is empty, else `false`. | |
#### Example | #### Example | |
skipping to change at line 3886 | skipping to change at line 4315 | |
_.isEmpty({ 'a': 1 }); | _.isEmpty({ 'a': 1 }); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_isequalvalue-other-customizer-thisarg"></a>`_.isEqual(value, other, | ### <a id="_isequalvalue-other"></a>`_.isEqual(value, other)` | |
[customizer], [thisArg])` | <a href="#_isequalvalue-other">#</a> [Ⓢ](https://github.com/lodash/lodash | |
<a href="#_isequalvalue-other-customizer-thisarg">#</a> [Ⓢ](https://githu | /blob/4.0.0/lodash.js#L9464 "View in source") [Ⓣ][1] [Ⓝ](https://w | |
b.com/lodash/lodash/blob/3.0.0/lodash.src.js#L7880 "View in source") [Ⓣ][ | ww.npmjs.com/package/lodash.isequal "See the npm package") | |
1] | ||
Performs a deep comparison between two values to determine if they are | Performs a deep comparison between two values to determine if they are | |
equivalent. If `customizer` is provided it is invoked to compare values. | equivalent. | |
If `customizer` returns `undefined` comparisons are handled by the method | <br> | |
instead. The `customizer` is bound to `thisArg` and invoked with three | <br> | |
arguments; (value, other [, index|key]). | **Note:** This method supports comparing arrays, array buffers, booleans, | |
*Note:** This method supports comparing arrays, booleans, `Date` objects, | date objects, error objects, maps, numbers, `Object` objects, regexes, | |
numbers, `Object` objects, regexes, and strings. Functions and DOM nodes | sets, strings, symbols, and typed arrays. `Object` objects are compared | |
are **not** supported. Provide a customizer function to extend support | by their own, not inherited, enumerable properties. Functions and DOM | |
for comparing other values. | nodes are **not** supported. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to compare. | 1. `value` *(*)*: The value to compare. | |
2. `other` *(*)*: The other value to compare. | 2. `other` *(*)*: The other value to compare. | |
3. `[customizer]` *(Function)*: The function to customize comparing values. | ||
4. `[thisArg]` *(*)*: The `this` binding of `customizer`. | ||
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if the values are equivalent, else `false`. | *(boolean)*: Returns `true` if the values are equivalent, else `false`. | |
#### Example | #### Example | |
```js | ```js | |
var object = { 'user': 'fred' }; | var object = { 'user': 'fred' }; | |
var other = { 'user': 'fred' }; | var other = { 'user': 'fred' }; | |
object == other; | ||
// => false | ||
_.isEqual(object, other); | _.isEqual(object, other); | |
// => true | // => true | |
// using a customizer callback | object === other; | |
// => false | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_isequalwithvalue-other-customizer"></a>`_.isEqualWith(value, other, | ||
[customizer])` | ||
<a href="#_isequalwithvalue-other-customizer">#</a> [Ⓢ](https://github.co | ||
m/lodash/lodash/blob/4.0.0/lodash.js#L9499 "View in source") [Ⓣ][1] [ | ||
4C3;](https://www.npmjs.com/package/lodash.isequalwith "See the npm package") | ||
This method is like `_.isEqual` except that it accepts `customizer` which is | ||
invoked to compare values. If `customizer` returns `undefined` comparisons are | ||
handled by the method instead. The `customizer` is invoked with up to seven argu | ||
ments:<br> | ||
(objValue, othValue [, index|key, object, other, stack]). | ||
#### Arguments | ||
1. `value` *(*)*: The value to compare. | ||
2. `other` *(*)*: The other value to compare. | ||
3. `[customizer]` *(Function)*: The function to customize comparisons. | ||
#### Returns | ||
*(boolean)*: Returns `true` if the values are equivalent, else `false`. | ||
#### Example | ||
```js | ||
function isGreeting(value) { | ||
return /^h(?:i|ello)$/.test(value); | ||
} | ||
function customizer(objValue, othValue) { | ||
if (isGreeting(objValue) && isGreeting(othValue)) { | ||
return true; | ||
} | ||
} | ||
var array = ['hello', 'goodbye']; | var array = ['hello', 'goodbye']; | |
var other = ['hi', 'goodbye']; | var other = ['hi', 'goodbye']; | |
_.isEqual(array, other, function(value, other) { | _.isEqualWith(array, other, customizer); | |
return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || unde | ||
fined; | ||
}); | ||
// => true | // => true | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_iserrorvalue"></a>`_.isError(value)` | ### <a id="_iserrorvalue"></a>`_.isError(value)` | |
<a href="#_iserrorvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 3.0.0/lodash.src.js#L7906 "View in source") [Ⓣ][1] | <a href="#_iserrorvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 4.0.0/lodash.js#L9522 "View in source") [Ⓣ][1] [Ⓝ](https://www.npm js.com/package/lodash.iserror "See the npm package") | |
Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, | Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, | |
`SyntaxError`, `TypeError`, or `URIError` object. | `SyntaxError`, `TypeError`, or `URIError` object. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is an error object, else `false`. | *(boolean)*: Returns `true` if `value` is an error object, else `false`. | |
skipping to change at line 3961 | skipping to change at line 4419 | |
_.isError(Error); | _.isError(Error); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_isfinitevalue"></a>`_.isFinite(value)` | ### <a id="_isfinitevalue"></a>`_.isFinite(value)` | |
<a href="#_isfinitevalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob /3.0.0/lodash.src.js#L7939 "View in source") [Ⓣ][1] | <a href="#_isfinitevalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob /4.0.0/lodash.js#L9551 "View in source") [Ⓣ][1] [Ⓝ](https://www.np mjs.com/package/lodash.isfinite "See the npm package") | |
Checks if `value` is a finite primitive number. | Checks if `value` is a finite primitive number. | |
*Note:** This method is based on ES `Number.isFinite`. See the | <br> | |
[ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.isfin | <br> | |
ite) | **Note:** This method is based on [`Number.isFinite`](https://mdn.io/Number/isFi | |
for more details. | nite). | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is a finite number, else `false`. | *(boolean)*: Returns `true` if `value` is a finite number, else `false`. | |
#### Example | #### Example | |
```js | ```js | |
_.isFinite(10); | _.isFinite(3); | |
// => true | // => true | |
_.isFinite('10'); | _.isFinite(Number.MAX_VALUE); | |
// => false | // => true | |
_.isFinite(true); | ||
// => false | ||
_.isFinite(Object(10)); | _.isFinite(3.14); | |
// => false | // => true | |
_.isFinite(Infinity); | _.isFinite(Infinity); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_isfunctionvalue"></a>`_.isFunction(value)` | ### <a id="_isfunctionvalue"></a>`_.isFunction(value)` | |
<a href="#_isfunctionvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/bl ob/3.0.0/lodash.src.js#L7959 "View in source") [Ⓣ][1] | <a href="#_isfunctionvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/bl ob/4.0.0/lodash.js#L9571 "View in source") [Ⓣ][1] [Ⓝ](https://www. npmjs.com/package/lodash.isfunction "See the npm package") | |
Checks if `value` is classified as a `Function` object. | Checks if `value` is classified as a `Function` object. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | *(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | |
#### Example | #### Example | |
skipping to change at line 4022 | skipping to change at line 4477 | |
_.isFunction(/abc/); | _.isFunction(/abc/); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_ismatchsource-source-customizer-thisarg"></a>`_.isMatch(source, sour | ### <a id="_isintegervalue"></a>`_.isInteger(value)` | |
ce, [customizer], [thisArg])` | <a href="#_isintegervalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blo | |
<a href="#_ismatchsource-source-customizer-thisarg">#</a> [Ⓢ](https://git | b/4.0.0/lodash.js#L9603 "View in source") [Ⓣ][1] [Ⓝ](https://www.n | |
hub.com/lodash/lodash/blob/3.0.0/lodash.src.js#L8042 "View in source") [Ⓣ | pmjs.com/package/lodash.isinteger "See the npm package") | |
][1] | ||
Checks if `value` is an integer. | ||
<br> | ||
<br> | ||
**Note:** This method is based on [`Number.isInteger`](https://mdn.io/Number/isI | ||
nteger). | ||
#### Arguments | ||
1. `value` *(*)*: The value to check. | ||
#### Returns | ||
*(boolean)*: Returns `true` if `value` is an integer, else `false`. | ||
#### Example | ||
```js | ||
_.isInteger(3); | ||
// => true | ||
_.isInteger(Number.MIN_VALUE); | ||
// => false | ||
_.isInteger(Infinity); | ||
// => false | ||
_.isInteger('3'); | ||
// => false | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_islengthvalue"></a>`_.isLength(value)` | ||
<a href="#_islengthvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob | ||
/4.0.0/lodash.js#L9631 "View in source") [Ⓣ][1] [Ⓝ](https://www.np | ||
mjs.com/package/lodash.islength "See the npm package") | ||
Checks if `value` is a valid array-like length. | ||
<br> | ||
<br> | ||
**Note:** This function is loosely based on [`ToLength`](http://ecma-internation | ||
al.org/ecma-262/6.0/#sec-tolength). | ||
#### Arguments | ||
1. `value` *(*)*: The value to check. | ||
#### Returns | ||
*(boolean)*: Returns `true` if `value` is a valid length, else `false`. | ||
#### Example | ||
```js | ||
_.isLength(3); | ||
// => true | ||
_.isLength(Number.MIN_VALUE); | ||
// => false | ||
_.isLength(Infinity); | ||
// => false | ||
_.isLength('3'); | ||
// => false | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_ismatchobject-source"></a>`_.isMatch(object, source)` | ||
<a href="#_ismatchobject-source">#</a> [Ⓢ](https://github.com/lodash/loda | ||
sh/blob/4.0.0/lodash.js#L9714 "View in source") [Ⓣ][1] [Ⓝ](https:/ | ||
/www.npmjs.com/package/lodash.ismatch "See the npm package") | ||
Performs a deep comparison between `object` and `source` to determine if | Performs a deep comparison between `object` and `source` to determine if | |
`object` contains equivalent property values. If `customizer` is provided | `object` contains equivalent property values. | |
it is invoked to compare values. If `customizer` returns `undefined` | <br> | |
comparisons are handled by the method instead. The `customizer` is bound | <br> | |
to `thisArg` and invoked with three arguments; (value, other, index|key). | **Note:** This method supports comparing the same values as `_.isEqual`. | |
*Note:** This method supports comparing properties of arrays, booleans, | ||
`Date` objects, numbers, `Object` objects, regexes, and strings. Functions | ||
and DOM nodes are **not** supported. Provide a customizer function to extend | ||
support for comparing other values. | ||
#### Arguments | #### Arguments | |
1. `source` *(Object)*: The object to inspect. | 1. `object` *(Object)*: The object to inspect. | |
2. `source` *(Object)*: The object of property values to match. | 2. `source` *(Object)*: The object of property values to match. | |
3. `[customizer]` *(Function)*: The function to customize comparing values. | ||
4. `[thisArg]` *(*)*: The `this` binding of `customizer`. | ||
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `object` is a match, else `false`. | *(boolean)*: Returns `true` if `object` is a match, else `false`. | |
#### Example | #### Example | |
```js | ```js | |
var object = { 'user': 'fred', 'age': 40 }; | var object = { 'user': 'fred', 'age': 40 }; | |
_.isMatch(object, { 'age': 40 }); | _.isMatch(object, { 'age': 40 }); | |
// => true | // => true | |
_.isMatch(object, { 'age': 36 }); | _.isMatch(object, { 'age': 36 }); | |
// => false | // => false | |
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_ismatchwithobject-source-customizer"></a>`_.isMatchWith(object, sour | ||
ce, [customizer])` | ||
<a href="#_ismatchwithobject-source-customizer">#</a> [Ⓢ](https://github. | ||
com/lodash/lodash/blob/4.0.0/lodash.js#L9749 "View in source") [Ⓣ][1] [&# | ||
x24C3;](https://www.npmjs.com/package/lodash.ismatchwith "See the npm package") | ||
This method is like `_.isMatch` except that it accepts `customizer` which | ||
is invoked to compare values. If `customizer` returns `undefined` comparisons | ||
are handled by the method instead. The `customizer` is invoked with three | ||
arguments: (objValue, srcValue, index|key, object, source). | ||
#### Arguments | ||
1. `object` *(Object)*: The object to inspect. | ||
2. `source` *(Object)*: The object of property values to match. | ||
3. `[customizer]` *(Function)*: The function to customize comparisons. | ||
#### Returns | ||
*(boolean)*: Returns `true` if `object` is a match, else `false`. | ||
#### Example | ||
```js | ||
function isGreeting(value) { | ||
return /^h(?:i|ello)$/.test(value); | ||
} | ||
function customizer(objValue, srcValue) { | ||
if (isGreeting(objValue) && isGreeting(srcValue)) { | ||
return true; | ||
} | ||
} | ||
// using a customizer callback | ||
var object = { 'greeting': 'hello' }; | var object = { 'greeting': 'hello' }; | |
var source = { 'greeting': 'hi' }; | var source = { 'greeting': 'hi' }; | |
_.isMatch(object, source, function(value, other) { | _.isMatchWith(object, source, customizer); | |
return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || unde | ||
fined; | ||
}); | ||
// => true | // => true | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_isnanvalue"></a>`_.isNaN(value)` | ### <a id="_isnanvalue"></a>`_.isNaN(value)` | |
<a href="#_isnanvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3. 0.0/lodash.src.js#L8091 "View in source") [Ⓣ][1] | <a href="#_isnanvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4. 0.0/lodash.js#L9779 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs .com/package/lodash.isnan "See the npm package") | |
Checks if `value` is `NaN`. | Checks if `value` is `NaN`. | |
*Note:** This method is not the same as native `isNaN` which returns `true` | <br> | |
for `undefined` and other non-numeric values. See the [ES5 spec](https://es5.git | <br> | |
hub.io/#x15.1.2.4) | **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1. | |
for more details. | 2.4) | |
which returns `true` for `undefined` and other non-numeric values. | ||
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is `NaN`, else `false`. | *(boolean)*: Returns `true` if `value` is `NaN`, else `false`. | |
#### Example | #### Example | |
```js | ```js | |
_.isNaN(NaN); | _.isNaN(NaN); | |
skipping to change at line 4104 | skipping to change at line 4653 | |
_.isNaN(undefined); | _.isNaN(undefined); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_isnativevalue"></a>`_.isNative(value)` | ### <a id="_isnativevalue"></a>`_.isNative(value)` | |
<a href="#_isnativevalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob /3.0.0/lodash.src.js#L8113 "View in source") [Ⓣ][1] | <a href="#_isnativevalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob /4.0.0/lodash.js#L9801 "View in source") [Ⓣ][1] [Ⓝ](https://www.np mjs.com/package/lodash.isnative "See the npm package") | |
Checks if `value` is a native function. | Checks if `value` is a native function. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is a native function, else `false`. | *(boolean)*: Returns `true` if `value` is a native function, else `false`. | |
#### Example | #### Example | |
skipping to change at line 4128 | skipping to change at line 4677 | |
_.isNative(_); | _.isNative(_); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_isnilvalue"></a>`_.isNil(value)` | ||
<a href="#_isnilvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4. | ||
0.0/lodash.js#L9851 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs | ||
.com/package/lodash.isnil "See the npm package") | ||
Checks if `value` is `null` or `undefined`. | ||
#### Arguments | ||
1. `value` *(*)*: The value to check. | ||
#### Returns | ||
*(boolean)*: Returns `true` if `value` is nullish, else `false`. | ||
#### Example | ||
```js | ||
_.isNil(null); | ||
// => true | ||
_.isNil(void 0); | ||
// => true | ||
_.isNil(NaN); | ||
// => false | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_isnullvalue"></a>`_.isNull(value)` | ### <a id="_isnullvalue"></a>`_.isNull(value)` | |
<a href="#_isnullvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3 .0.0/lodash.src.js#L8140 "View in source") [Ⓣ][1] | <a href="#_isnullvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4 .0.0/lodash.js#L9828 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmj s.com/package/lodash.isnull "See the npm package") | |
Checks if `value` is `null`. | Checks if `value` is `null`. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is `null`, else `false`. | *(boolean)*: Returns `true` if `value` is `null`, else `false`. | |
#### Example | #### Example | |
skipping to change at line 4154 | skipping to change at line 4731 | |
_.isNull(void 0); | _.isNull(void 0); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_isnumbervalue"></a>`_.isNumber(value)` | ### <a id="_isnumbervalue"></a>`_.isNumber(value)` | |
<a href="#_isnumbervalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob /3.0.0/lodash.src.js#L8166 "View in source") [Ⓣ][1] | <a href="#_isnumbervalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob /4.0.0/lodash.js#L9880 "View in source") [Ⓣ][1] [Ⓝ](https://www.np mjs.com/package/lodash.isnumber "See the npm package") | |
Checks if `value` is classified as a `Number` primitive or object. | Checks if `value` is classified as a `Number` primitive or object. | |
*Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified | <br> | |
<br> | ||
**Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified | ||
as numbers, use the `_.isFinite` method. | as numbers, use the `_.isFinite` method. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | *(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | |
#### Example | #### Example | |
```js | ```js | |
_.isNumber(8.4); | _.isNumber(3); | |
// => true | ||
_.isNumber(Number.MIN_VALUE); | ||
// => true | // => true | |
_.isNumber(NaN); | _.isNumber(Infinity); | |
// => true | // => true | |
_.isNumber('8.4'); | _.isNumber('3'); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_isobjectvalue"></a>`_.isObject(value)` | ### <a id="_isobjectvalue"></a>`_.isObject(value)` | |
<a href="#_isobjectvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob /3.0.0/lodash.src.js#L7996 "View in source") [Ⓣ][1] | <a href="#_isobjectvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob /4.0.0/lodash.js#L9658 "View in source") [Ⓣ][1] [Ⓝ](https://www.np mjs.com/package/lodash.isobject "See the npm package") | |
Checks if `value` is the language type of `Object`. | Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. | |
(e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')` ) | (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')` ) | |
*Note:** See the [ES5 spec](https://es5.github.io/#x8) for more details. | ||
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is an object, else `false`. | *(boolean)*: Returns `true` if `value` is an object, else `false`. | |
#### Example | #### Example | |
```js | ```js | |
_.isObject({}); | _.isObject({}); | |
// => true | // => true | |
_.isObject([1, 2, 3]); | _.isObject([1, 2, 3]); | |
// => true | // => true | |
_.isObject(1); | _.isObject(_.noop); | |
// => true | ||
_.isObject(null); | ||
// => false | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_isobjectlikevalue"></a>`_.isObjectLike(value)` | ||
<a href="#_isobjectlikevalue">#</a> [Ⓢ](https://github.com/lodash/lodash/ | ||
blob/4.0.0/lodash.js#L9688 "View in source") [Ⓣ][1] [Ⓝ](https://ww | ||
w.npmjs.com/package/lodash.isobjectlike "See the npm package") | ||
Checks if `value` is object-like. A value is object-like if it's not `null` | ||
and has a `typeof` result of "object". | ||
#### Arguments | ||
1. `value` *(*)*: The value to check. | ||
#### Returns | ||
*(boolean)*: Returns `true` if `value` is object-like, else `false`. | ||
#### Example | ||
```js | ||
_.isObjectLike({}); | ||
// => true | ||
_.isObjectLike([1, 2, 3]); | ||
// => true | ||
_.isObjectLike(_.noop); | ||
// => false | ||
_.isObjectLike(null); | ||
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_isplainobjectvalue"></a>`_.isPlainObject(value)` | ### <a id="_isplainobjectvalue"></a>`_.isPlainObject(value)` | |
<a href="#_isplainobjectvalue">#</a> [Ⓢ](https://github.com/lodash/lodash /blob/3.0.0/lodash.src.js#L8200 "View in source") [Ⓣ][1] | <a href="#_isplainobjectvalue">#</a> [Ⓢ](https://github.com/lodash/lodash /blob/4.0.0/lodash.js#L9912 "View in source") [Ⓣ][1] [Ⓝ](https://w ww.npmjs.com/package/lodash.isplainobject "See the npm package") | |
Checks if `value` is a plain object, that is, an object created by the | Checks if `value` is a plain object, that is, an object created by the | |
`Object` constructor or one with a `[[Prototype]]` of `null`. | `Object` constructor or one with a `[[Prototype]]` of `null`. | |
*Note:** This method assumes objects created by the `Object` constructor | ||
have no inherited enumerable properties. | ||
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is a plain object, else `false`. | *(boolean)*: Returns `true` if `value` is a plain object, else `false`. | |
#### Example | #### Example | |
```js | ```js | |
function Foo() { | function Foo() { | |
skipping to change at line 4252 | skipping to change at line 4866 | |
_.isPlainObject(Object.create(null)); | _.isPlainObject(Object.create(null)); | |
// => true | // => true | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_isregexpvalue"></a>`_.isRegExp(value)` | ### <a id="_isregexpvalue"></a>`_.isRegExp(value)` | |
<a href="#_isregexpvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob /3.0.0/lodash.src.js#L8228 "View in source") [Ⓣ][1] | <a href="#_isregexpvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob /4.0.0/lodash.js#L9944 "View in source") [Ⓣ][1] [Ⓝ](https://www.np mjs.com/package/lodash.isregexp "See the npm package") | |
Checks if `value` is classified as a `RegExp` object. | Checks if `value` is classified as a `RegExp` object. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | *(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | |
#### Example | #### Example | |
skipping to change at line 4276 | skipping to change at line 4890 | |
_.isRegExp('/abc/'); | _.isRegExp('/abc/'); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_issafeintegervalue"></a>`_.isSafeInteger(value)` | ||
<a href="#_issafeintegervalue">#</a> [Ⓢ](https://github.com/lodash/lodash | ||
/blob/4.0.0/lodash.js#L9973 "View in source") [Ⓣ][1] [Ⓝ](https://w | ||
ww.npmjs.com/package/lodash.issafeinteger "See the npm package") | ||
Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754 | ||
double precision number which isn't the result of a rounded unsafe integer. | ||
<br> | ||
<br> | ||
**Note:** This method is based on [`Number.isSafeInteger`](https://mdn.io/Number | ||
/isSafeInteger). | ||
#### Arguments | ||
1. `value` *(*)*: The value to check. | ||
#### Returns | ||
*(boolean)*: Returns `true` if `value` is a safe integer, else `false`. | ||
#### Example | ||
```js | ||
_.isSafeInteger(3); | ||
// => true | ||
_.isSafeInteger(Number.MIN_VALUE); | ||
// => false | ||
_.isSafeInteger(Infinity); | ||
// => false | ||
_.isSafeInteger('3'); | ||
// => false | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_isstringvalue"></a>`_.isString(value)` | ### <a id="_isstringvalue"></a>`_.isString(value)` | |
<a href="#_isstringvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob /3.0.0/lodash.src.js#L8248 "View in source") [Ⓣ][1] | <a href="#_isstringvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob /4.0.0/lodash.js#L9993 "View in source") [Ⓣ][1] [Ⓝ](https://www.np mjs.com/package/lodash.isstring "See the npm package") | |
Checks if `value` is classified as a `String` primitive or object. | Checks if `value` is classified as a `String` primitive or object. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | *(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | |
#### Example | #### Example | |
skipping to change at line 4301 | skipping to change at line 4950 | |
_.isString(1); | _.isString(1); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_issymbolvalue"></a>`_.isSymbol(value)` | ||
<a href="#_issymbolvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob | ||
/4.0.0/lodash.js#L10014 "View in source") [Ⓣ][1] [Ⓝ](https://www.n | ||
pmjs.com/package/lodash.issymbol "See the npm package") | ||
Checks if `value` is classified as a `Symbol` primitive or object. | ||
#### Arguments | ||
1. `value` *(*)*: The value to check. | ||
#### Returns | ||
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | ||
#### Example | ||
```js | ||
_.isSymbol(Symbol.iterator); | ||
// => true | ||
_.isSymbol('abc'); | ||
// => false | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_istypedarrayvalue"></a>`_.isTypedArray(value)` | ### <a id="_istypedarrayvalue"></a>`_.isTypedArray(value)` | |
<a href="#_istypedarrayvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/ blob/3.0.0/lodash.src.js#L8268 "View in source") [Ⓣ][1] | <a href="#_istypedarrayvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/ blob/4.0.0/lodash.js#L10035 "View in source") [Ⓣ][1] [Ⓝ](https://w ww.npmjs.com/package/lodash.istypedarray "See the npm package") | |
Checks if `value` is classified as a typed array. | Checks if `value` is classified as a typed array. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | *(boolean)*: Returns `true` if `value` is correctly classified, else `false`. | |
#### Example | #### Example | |
skipping to change at line 4327 | skipping to change at line 5001 | |
_.isTypedArray([]); | _.isTypedArray([]); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_isundefinedvalue"></a>`_.isUndefined(value)` | ### <a id="_isundefinedvalue"></a>`_.isUndefined(value)` | |
<a href="#_isundefinedvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/b lob/3.0.0/lodash.src.js#L8288 "View in source") [Ⓣ][1] | <a href="#_isundefinedvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/b lob/4.0.0/lodash.js#L10055 "View in source") [Ⓣ][1] [Ⓝ](https://ww w.npmjs.com/package/lodash.isundefined "See the npm package") | |
Checks if `value` is `undefined`. | Checks if `value` is `undefined`. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to check. | 1. `value` *(*)*: The value to check. | |
#### Returns | #### Returns | |
*(boolean)*: Returns `true` if `value` is `undefined`, else `false`. | *(boolean)*: Returns `true` if `value` is `undefined`, else `false`. | |
#### Example | #### Example | |
skipping to change at line 4351 | skipping to change at line 5025 | |
_.isUndefined(null); | _.isUndefined(null); | |
// => false | // => false | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_ltvalue-other"></a>`_.lt(value, other)` | ||
<a href="#_ltvalue-other">#</a> [Ⓢ](https://github.com/lodash/lodash/blob | ||
/4.0.0/lodash.js#L10079 "View in source") [Ⓣ][1] [Ⓝ](https://www.n | ||
pmjs.com/package/lodash.lt "See the npm package") | ||
Checks if `value` is less than `other`. | ||
#### Arguments | ||
1. `value` *(*)*: The value to compare. | ||
2. `other` *(*)*: The other value to compare. | ||
#### Returns | ||
*(boolean)*: Returns `true` if `value` is less than `other`, else `false`. | ||
#### Example | ||
```js | ||
_.lt(1, 3); | ||
// => true | ||
_.lt(3, 3); | ||
// => false | ||
_.lt(3, 1); | ||
// => false | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_ltevalue-other"></a>`_.lte(value, other)` | ||
<a href="#_ltevalue-other">#</a> [Ⓢ](https://github.com/lodash/lodash/blo | ||
b/4.0.0/lodash.js#L10103 "View in source") [Ⓣ][1] [Ⓝ](https://www. | ||
npmjs.com/package/lodash.lte "See the npm package") | ||
Checks if `value` is less than or equal to `other`. | ||
#### Arguments | ||
1. `value` *(*)*: The value to compare. | ||
2. `other` *(*)*: The other value to compare. | ||
#### Returns | ||
*(boolean)*: Returns `true` if `value` is less than or equal to `other`, else ` | ||
false`. | ||
#### Example | ||
```js | ||
_.lte(1, 3); | ||
// => true | ||
_.lte(3, 3); | ||
// => true | ||
_.lte(3, 1); | ||
// => false | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_toarrayvalue"></a>`_.toArray(value)` | ### <a id="_toarrayvalue"></a>`_.toArray(value)` | |
<a href="#_toarrayvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 3.0.0/lodash.src.js#L8305 "View in source") [Ⓣ][1] | <a href="#_toarrayvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/ 4.0.0/lodash.js#L10129 "View in source") [Ⓣ][1] [Ⓝ](https://www.np mjs.com/package/lodash.toarray "See the npm package") | |
Converts `value` to an array. | Converts `value` to an array. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to convert. | 1. `value` *(*)*: The value to convert. | |
#### Returns | #### Returns | |
*(Array)*: Returns the converted array. | *(Array)*: Returns the converted array. | |
#### Example | #### Example | |
```js | ```js | |
(function() { return _.toArray(arguments).slice(1); })(1, 2, 3); | _.toArray({ 'a': 1, 'b': 2 }); | |
// => [2, 3] | // => [1, 2] | |
_.toArray('abc'); | ||
// => ['a', 'b', 'c'] | ||
_.toArray(1); | ||
// => [] | ||
_.toArray(null); | ||
// => [] | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_tointegervalue"></a>`_.toInteger(value)` | ||
<a href="#_tointegervalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blo | ||
b/4.0.0/lodash.js#L10169 "View in source") [Ⓣ][1] [Ⓝ](https://www. | ||
npmjs.com/package/lodash.tointeger "See the npm package") | ||
Converts `value` to an integer. | ||
<br> | ||
<br> | ||
**Note:** This function is loosely based on [`ToInteger`](http://www.ecma-intern | ||
ational.org/ecma-262/6.0/#sec-tointeger). | ||
#### Arguments | ||
1. `value` *(*)*: The value to convert. | ||
#### Returns | ||
*(number)*: Returns the converted integer. | ||
#### Example | ||
```js | ||
_.toInteger(3); | ||
// => 3 | ||
_.toInteger(Number.MIN_VALUE); | ||
// => 0 | ||
_.toInteger(Infinity); | ||
// => 1.7976931348623157e+308 | ||
_.toInteger('3'); | ||
// => 3 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_tolengthvalue"></a>`_.toLength(value)` | ||
<a href="#_tolengthvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob | ||
/4.0.0/lodash.js#L10207 "View in source") [Ⓣ][1] [Ⓝ](https://www.n | ||
pmjs.com/package/lodash.tolength "See the npm package") | ||
Converts `value` to an integer suitable for use as the length of an | ||
array-like object. | ||
<br> | ||
<br> | ||
**Note:** This method is based on [`ToLength`](http://ecma-international.org/ecm | ||
a-262/6.0/#sec-tolength). | ||
#### Arguments | ||
1. `value` *(*)*: The value to convert. | ||
#### Example | ||
```js | ||
_.toLength(3); | ||
// => 3 | ||
_.toLength(Number.MIN_VALUE); | ||
// => 0 | ||
_.toLength(Infinity); | ||
// => 4294967295 | ||
_.toLength('3'); | ||
// => 3 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_tonumbervalue"></a>`_.toNumber(value)` | ||
<a href="#_tonumbervalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob | ||
/4.0.0/lodash.js#L10233 "View in source") [Ⓣ][1] [Ⓝ](https://www.n | ||
pmjs.com/package/lodash.tonumber "See the npm package") | ||
Converts `value` to a number. | ||
#### Arguments | ||
1. `value` *(*)*: The value to process. | ||
#### Returns | ||
*(number)*: Returns the number. | ||
#### Example | ||
```js | ||
_.toNumber(3); | ||
// => 3 | ||
_.toNumber(Number.MIN_VALUE); | ||
// => 5e-324 | ||
_.toNumber(Infinity); | ||
// => Infinity | ||
_.toNumber('3'); | ||
// => 3 | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_toplainobjectvalue"></a>`_.toPlainObject(value)` | ### <a id="_toplainobjectvalue"></a>`_.toPlainObject(value)` | |
<a href="#_toplainobjectvalue">#</a> [Ⓢ](https://github.com/lodash/lodash /blob/3.0.0/lodash.src.js#L8341 "View in source") [Ⓣ][1] | <a href="#_toplainobjectvalue">#</a> [Ⓢ](https://github.com/lodash/lodash /blob/4.0.0/lodash.js#L10271 "View in source") [Ⓣ][1] [Ⓝ](https:// www.npmjs.com/package/lodash.toplainobject "See the npm package") | |
Converts `value` to a plain object flattening inherited enumerable | Converts `value` to a plain object flattening inherited enumerable | |
properties of `value` to own properties of the plain object. | properties of `value` to own properties of the plain object. | |
#### Arguments | #### Arguments | |
1. `value` *(*)*: The value to convert. | 1. `value` *(*)*: The value to convert. | |
#### Returns | #### Returns | |
*(Object)*: Returns the converted plain object. | *(Object)*: Returns the converted plain object. | |
skipping to change at line 4403 | skipping to change at line 5241 | |
_.assign({ 'a': 1 }, new Foo); | _.assign({ 'a': 1 }, new Foo); | |
// => { 'a': 1, 'b': 2 } | // => { 'a': 1, 'b': 2 } | |
_.assign({ 'a': 1 }, _.toPlainObject(new Foo)); | _.assign({ 'a': 1 }, _.toPlainObject(new Foo)); | |
// => { 'a': 1, 'b': 2, 'c': 3 } | // => { 'a': 1, 'b': 2, 'c': 3 } | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | ||
### <a id="_tosafeintegervalue"></a>`_.toSafeInteger(value)` | ||
<a href="#_tosafeintegervalue">#</a> [Ⓢ](https://github.com/lodash/lodash | ||
/blob/4.0.0/lodash.js#L10298 "View in source") [Ⓣ][1] [Ⓝ](https:// | ||
www.npmjs.com/package/lodash.tosafeinteger "See the npm package") | ||
Converts `value` to a safe integer. A safe integer can be compared and | ||
represented correctly. | ||
#### Arguments | ||
1. `value` *(*)*: The value to convert. | ||
#### Returns | ||
*(number)*: Returns the converted integer. | ||
#### Example | ||
```js | ||
_.toSafeInteger(3); | ||
// => 3 | ||
_.toSafeInteger(Number.MIN_VALUE); | ||
// => 0 | ||
_.toSafeInteger(Infinity); | ||
// => 9007199254740991 | ||
_.toSafeInteger('3'); | ||
// => 3 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_tostringvalue"></a>`_.toString(value)` | ||
<a href="#_tostringvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob | ||
/4.0.0/lodash.js#L10322 "View in source") [Ⓣ][1] [Ⓝ](https://www.n | ||
pmjs.com/package/lodash.tostring "See the npm package") | ||
Converts `value` to a string if it's not one. An empty string is returned | ||
for `null` and `undefined` values. The sign of `-0` is preserved. | ||
#### Arguments | ||
1. `value` *(*)*: The value to process. | ||
#### Returns | ||
*(string)*: Returns the string. | ||
#### Example | ||
```js | ||
_.toString(null); | ||
// => '' | ||
_.toString(-0); | ||
// => '-0' | ||
_.toString([1, 2, 3]); | ||
// => '1,2,3' | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- /div --> | ||
<!-- div --> | ||
## `“Math” Methods` | ||
<!-- div --> | ||
### <a id="_addaugend-addend"></a>`_.add(augend, addend)` | ||
<a href="#_addaugend-addend">#</a> [Ⓢ](https://github.com/lodash/lodash/b | ||
lob/4.0.0/lodash.js#L13547 "View in source") [Ⓣ][1] [Ⓝ](https://ww | ||
w.npmjs.com/package/lodash.add "See the npm package") | ||
Adds two numbers. | ||
#### Arguments | ||
1. `augend` *(number)*: The first number in an addition. | ||
2. `addend` *(number)*: The second number in an addition. | ||
#### Returns | ||
*(number)*: Returns the total. | ||
#### Example | ||
```js | ||
_.add(6, 4); | ||
// => 10 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_ceilnumber-precision0"></a>`_.ceil(number, [precision=0])` | ||
<a href="#_ceilnumber-precision0">#</a> [Ⓢ](https://github.com/lodash/lod | ||
ash/blob/4.0.0/lodash.js#L13578 "View in source") [Ⓣ][1] [Ⓝ](https | ||
://www.npmjs.com/package/lodash.ceil "See the npm package") | ||
Computes `number` rounded up to `precision`. | ||
#### Arguments | ||
1. `number` *(number)*: The number to round up. | ||
2. `[precision=0]` *(number)*: The precision to round up to. | ||
#### Returns | ||
*(number)*: Returns the rounded up number. | ||
#### Example | ||
```js | ||
_.ceil(4.006); | ||
// => 5 | ||
_.ceil(6.004, 2); | ||
// => 6.01 | ||
_.ceil(6040, -2); | ||
// => 6100 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_floornumber-precision0"></a>`_.floor(number, [precision=0])` | ||
<a href="#_floornumber-precision0">#</a> [Ⓢ](https://github.com/lodash/lo | ||
dash/blob/4.0.0/lodash.js#L13600 "View in source") [Ⓣ][1] [Ⓝ](http | ||
s://www.npmjs.com/package/lodash.floor "See the npm package") | ||
Computes `number` rounded down to `precision`. | ||
#### Arguments | ||
1. `number` *(number)*: The number to round down. | ||
2. `[precision=0]` *(number)*: The precision to round down to. | ||
#### Returns | ||
*(number)*: Returns the rounded down number. | ||
#### Example | ||
```js | ||
_.floor(4.006); | ||
// => 4 | ||
_.floor(0.046, 2); | ||
// => 0.04 | ||
_.floor(4060, -2); | ||
// => 4000 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_maxarray"></a>`_.max(array)` | ||
<a href="#_maxarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4.0. | ||
0/lodash.js#L13619 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs. | ||
com/package/lodash.max "See the npm package") | ||
Computes the maximum value of `array`. If `array` is empty or falsey | ||
`undefined` is returned. | ||
#### Arguments | ||
1. `array` *(Array)*: The array to iterate over. | ||
#### Returns | ||
*(*)*: Returns the maximum value. | ||
#### Example | ||
```js | ||
_.max([4, 2, 8, 6]); | ||
// => 8 | ||
_.max([]); | ||
// => undefined | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_maxbyarray-iteratee_identity"></a>`_.maxBy(array, [iteratee=_.identi | ||
ty])` | ||
<a href="#_maxbyarray-iteratee_identity">#</a> [Ⓢ](https://github.com/lod | ||
ash/lodash/blob/4.0.0/lodash.js#L13647 "View in source") [Ⓣ][1] [Ⓝ | ||
](https://www.npmjs.com/package/lodash.maxby "See the npm package") | ||
This method is like `_.max` except that it accepts `iteratee` which is | ||
invoked for each element in `array` to generate the criterion by which | ||
the value is ranked. The iteratee is invoked with one argument: (value). | ||
#### Arguments | ||
1. `array` *(Array)*: The array to iterate over. | ||
2. `[iteratee=_.identity]` *(Function|Object|string)*: The iteratee invoked per | ||
element. | ||
#### Returns | ||
*(*)*: Returns the maximum value. | ||
#### Example | ||
```js | ||
var objects = [{ 'n': 1 }, { 'n': 2 }]; | ||
_.maxBy(objects, function(o) { return o.a; }); | ||
// => { 'n': 2 } | ||
// using the `_.property` iteratee shorthand | ||
_.maxBy(objects, 'n'); | ||
// => { 'n': 2 } | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_meanarray"></a>`_.mean(array)` | ||
<a href="#_meanarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4.0 | ||
.0/lodash.js#L13666 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs | ||
.com/package/lodash.mean "See the npm package") | ||
Computes the mean of the values in `array`. | ||
#### Arguments | ||
1. `array` *(Array)*: The array to iterate over. | ||
#### Returns | ||
*(number)*: Returns the mean. | ||
#### Example | ||
```js | ||
_.mean([4, 2, 8, 6]); | ||
// => 5 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_minarray"></a>`_.min(array)` | ||
<a href="#_minarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4.0. | ||
0/lodash.js#L13687 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs. | ||
com/package/lodash.min "See the npm package") | ||
Computes the minimum value of `array`. If `array` is empty or falsey | ||
`undefined` is returned. | ||
#### Arguments | ||
1. `array` *(Array)*: The array to iterate over. | ||
#### Returns | ||
*(*)*: Returns the minimum value. | ||
#### Example | ||
```js | ||
_.min([4, 2, 8, 6]); | ||
// => 2 | ||
_.min([]); | ||
// => undefined | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_minbyarray-iteratee_identity"></a>`_.minBy(array, [iteratee=_.identi | ||
ty])` | ||
<a href="#_minbyarray-iteratee_identity">#</a> [Ⓢ](https://github.com/lod | ||
ash/lodash/blob/4.0.0/lodash.js#L13715 "View in source") [Ⓣ][1] [Ⓝ | ||
](https://www.npmjs.com/package/lodash.minby "See the npm package") | ||
This method is like `_.min` except that it accepts `iteratee` which is | ||
invoked for each element in `array` to generate the criterion by which | ||
the value is ranked. The iteratee is invoked with one argument: (value). | ||
#### Arguments | ||
1. `array` *(Array)*: The array to iterate over. | ||
2. `[iteratee=_.identity]` *(Function|Object|string)*: The iteratee invoked per | ||
element. | ||
#### Returns | ||
*(*)*: Returns the minimum value. | ||
#### Example | ||
```js | ||
var objects = [{ 'n': 1 }, { 'n': 2 }]; | ||
_.minBy(objects, function(o) { return o.a; }); | ||
// => { 'n': 1 } | ||
// using the `_.property` iteratee shorthand | ||
_.minBy(objects, 'n'); | ||
// => { 'n': 1 } | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_roundnumber-precision0"></a>`_.round(number, [precision=0])` | ||
<a href="#_roundnumber-precision0">#</a> [Ⓢ](https://github.com/lodash/lo | ||
dash/blob/4.0.0/lodash.js#L13741 "View in source") [Ⓣ][1] [Ⓝ](http | ||
s://www.npmjs.com/package/lodash.round "See the npm package") | ||
Computes `number` rounded to `precision`. | ||
#### Arguments | ||
1. `number` *(number)*: The number to round. | ||
2. `[precision=0]` *(number)*: The precision to round to. | ||
#### Returns | ||
*(number)*: Returns the rounded number. | ||
#### Example | ||
```js | ||
_.round(4.006); | ||
// => 4 | ||
_.round(4.006, 2); | ||
// => 4.01 | ||
_.round(4060, -2); | ||
// => 4100 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_subtractminuend-subtrahend"></a>`_.subtract(minuend, subtrahend)` | ||
<a href="#_subtractminuend-subtrahend">#</a> [Ⓢ](https://github.com/lodas | ||
h/lodash/blob/4.0.0/lodash.js#L13757 "View in source") [Ⓣ][1] [Ⓝ]( | ||
https://www.npmjs.com/package/lodash.subtract "See the npm package") | ||
Subtract two numbers. | ||
#### Arguments | ||
1. `minuend` *(number)*: The first number in a subtraction. | ||
2. `subtrahend` *(number)*: The second number in a subtraction. | ||
#### Returns | ||
*(number)*: Returns the difference. | ||
#### Example | ||
```js | ||
_.subtract(6, 4); | ||
// => 2 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_sumarray"></a>`_.sum(array)` | ||
<a href="#_sumarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/4.0. | ||
0/lodash.js#L13781 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs. | ||
com/package/lodash.sum "See the npm package") | ||
Computes the sum of the values in `array`. | ||
#### Arguments | ||
1. `array` *(Array)*: The array to iterate over. | ||
#### Returns | ||
*(number)*: Returns the sum. | ||
#### Example | ||
```js | ||
_.sum([4, 2, 8, 6]); | ||
// => 20 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_sumbyarray-iteratee_identity"></a>`_.sumBy(array, [iteratee=_.identi | ||
ty])` | ||
<a href="#_sumbyarray-iteratee_identity">#</a> [Ⓢ](https://github.com/lod | ||
ash/lodash/blob/4.0.0/lodash.js#L13809 "View in source") [Ⓣ][1] [Ⓝ | ||
](https://www.npmjs.com/package/lodash.sumby "See the npm package") | ||
This method is like `_.sum` except that it accepts `iteratee` which is | ||
invoked for each element in `array` to generate the value to be summed. | ||
The iteratee is invoked with one argument: (value). | ||
#### Arguments | ||
1. `array` *(Array)*: The array to iterate over. | ||
2. `[iteratee=_.identity]` *(Function|Object|string)*: The iteratee invoked per | ||
element. | ||
#### Returns | ||
*(number)*: Returns the sum. | ||
#### Example | ||
```js | ||
var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }]; | ||
_.sumBy(objects, function(o) { return o.n; }); | ||
// => 20 | ||
// using the `_.property` iteratee shorthand | ||
_.sumBy(objects, 'n'); | ||
// => 20 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
## `“Number” Methods` | ## `“Number” Methods` | |
<!-- div --> | <!-- div --> | |
### <a id="_randommin0-max1-floating"></a>`_.random([min=0], [max=1], [floating] | ### <a id="_clampnumber-lower-upper"></a>`_.clamp(number, [lower], upper)` | |
)` | <a href="#_clampnumber-lower-upper">#</a> [Ⓢ](https://github.com/lodash/l | |
<a href="#_randommin0-max1-floating">#</a> [Ⓢ](https://github.com/lodash/ | odash/blob/4.0.0/lodash.js#L11575 "View in source") [Ⓣ][1] [Ⓝ](htt | |
lodash/blob/3.0.0/lodash.src.js#L9228 "View in source") [Ⓣ][1] | ps://www.npmjs.com/package/lodash.clamp "See the npm package") | |
Clamps `number` within the inclusive `lower` and `upper` bounds. | ||
#### Arguments | ||
1. `number` *(number)*: The number to clamp. | ||
2. `[lower]` *(number)*: The lower bound. | ||
3. `upper` *(number)*: The upper bound. | ||
#### Returns | ||
*(number)*: Returns the clamped number. | ||
#### Example | ||
```js | ||
_.clamp(-10, -5, 5); | ||
// => -5 | ||
_.clamp(10, -5, 5); | ||
// => 5 | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_inrangenumber-start0-end"></a>`_.inRange(number, [start=0], end)` | ||
<a href="#_inrangenumber-start0-end">#</a> [Ⓢ](https://github.com/lodash/ | ||
lodash/blob/4.0.0/lodash.js#L11627 "View in source") [Ⓣ][1] [Ⓝ](ht | ||
tps://www.npmjs.com/package/lodash.inrange "See the npm package") | ||
Checks if `n` is between `start` and up to but not including, `end`. If | ||
`end` is not specified it's set to `start` with `start` then set to `0`. | ||
If `start` is greater than `end` the params are swapped to support | ||
negative ranges. | ||
#### Arguments | ||
1. `number` *(number)*: The number to check. | ||
2. `[start=0]` *(number)*: The start of the range. | ||
3. `end` *(number)*: The end of the range. | ||
#### Returns | ||
*(boolean)*: Returns `true` if `number` is in the range, else `false`. | ||
#### Example | ||
```js | ||
_.inRange(3, 2, 4); | ||
// => true | ||
_.inRange(4, 8); | ||
// => true | ||
_.inRange(4, 2); | ||
// => false | ||
_.inRange(2, 2); | ||
// => false | ||
_.inRange(1.2, 2); | ||
// => true | ||
_.inRange(5.2, 4); | ||
// => false | ||
_.inRange(-3, -2, -6); | ||
// => true | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_randomlower0-upper1-floating"></a>`_.random([lower=0], [upper=1], [f | ||
loating])` | ||
<a href="#_randomlower0-upper1-floating">#</a> [Ⓢ](https://github.com/lod | ||
ash/lodash/blob/4.0.0/lodash.js#L11669 "View in source") [Ⓣ][1] [Ⓝ | ||
](https://www.npmjs.com/package/lodash.random "See the npm package") | ||
Produces a random number between `min` and `max` (inclusive). If only one | Produces a random number between the inclusive `lower` and `upper` bounds. | |
argument is provided a number between `0` and the given number is returned. | If only one argument is provided a number between `0` and the given number | |
If `floating` is `true`, or either `min` or `max` are floats, a floating-point | is returned. If `floating` is `true`, or either `lower` or `upper` are floats, | |
number is returned instead of an integer. | a floating-point number is returned instead of an integer. | |
<br> | ||
<br> | ||
**Note:** JavaScript follows the IEEE-754 standard for resolving | ||
floating-point values which can produce unexpected results. | ||
#### Arguments | #### Arguments | |
1. `[min=0]` *(number)*: The minimum possible value. | 1. `[lower=0]` *(number)*: The lower bound. | |
2. `[max=1]` *(number)*: The maximum possible value. | 2. `[upper=1]` *(number)*: The upper bound. | |
3. `[floating]` *(boolean)*: Specify returning a floating-point number. | 3. `[floating]` *(boolean)*: Specify returning a floating-point number. | |
#### Returns | #### Returns | |
*(number)*: Returns the random number. | *(number)*: Returns the random number. | |
#### Example | #### Example | |
```js | ```js | |
_.random(0, 5); | _.random(0, 5); | |
// => an integer between 0 and 5 | // => an integer between 0 and 5 | |
skipping to change at line 4453 | skipping to change at line 5756 | |
<!-- /div --> | <!-- /div --> | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
## `“Object” Methods` | ## `“Object” Methods` | |
<!-- div --> | <!-- div --> | |
### <a id="_assignobject-sources-customizer-thisarg"></a>`_.assign(object, [sour | ### <a id="_assignobject-sources"></a>`_.assign(object, [sources])` | |
ces], [customizer], [thisArg])` | <a href="#_assignobject-sources">#</a> [Ⓢ](https://github.com/lodash/loda | |
<a href="#_assignobject-sources-customizer-thisarg">#</a> [Ⓢ](https://git | sh/blob/4.0.0/lodash.js#L10369 "View in source") [Ⓣ][1] [Ⓝ](https: | |
hub.com/lodash/lodash/blob/3.0.0/lodash.src.js#L8376 "View in source") [Ⓣ | //www.npmjs.com/package/lodash.assign "See the npm package") | |
][1] | ||
Assigns own enumerable properties of source object(s) to the destination | Assigns own enumerable properties of source objects to the destination | |
object. Subsequent sources overwrite property assignments of previous sources. | object. Source objects are applied from left to right. Subsequent sources | |
If `customizer` is provided it is invoked to produce the assigned values. | overwrite property assignments of previous sources. | |
The `customizer` is bound to `thisArg` and invoked with five arguments; | <br> | |
(objectValue, sourceValue, key, object, source). | <br> | |
**Note:** This method mutates `object` and is loosely based on | ||
[`Object.assign`](https://mdn.io/Object/assign). | ||
#### Arguments | #### Arguments | |
1. `object` *(Object)*: The destination object. | 1. `object` *(Object)*: The destination object. | |
2. `[sources]` *(...Object)*: The source objects. | 2. `[sources]` *(...Object)*: The source objects. | |
3. `[customizer]` *(Function)*: The function to customize assigning values. | ||
4. `[thisArg]` *(*)*: The `this` binding of `customizer`. | ||
#### Returns | #### Returns | |
*(Object)*: Returns `object`. | *(Object)*: Returns `object`. | |
#### Example | #### Example | |
```js | ```js | |
_.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' }); | function Foo() { | |
// => { 'user': 'fred', 'age': 40 } | this.c = 3; | |
} | ||
// using a customizer callback | function Bar() { | |
var defaults = _.partialRight(_.assign, function(value, other) { | this.e = 5; | |
return typeof value == 'undefined' ? other : value; | } | |
}); | ||
defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' }); | Foo.prototype.d = 4; | |
// => { 'user': 'barney', 'age': 36 } | Bar.prototype.f = 6; | |
_.assign({ 'a': 1 }, new Foo, new Bar); | ||
// => { 'a': 1, 'c': 3, 'e': 5 } | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_assigninobject-sources"></a>`_.assignIn(object, [sources])` | ||
<a href="#_assigninobject-sources">#</a> [Ⓢ](https://github.com/lodash/lo | ||
dash/blob/4.0.0/lodash.js#L10402 "View in source") [Ⓣ][1] [Ⓝ](http | ||
s://www.npmjs.com/package/lodash.assignin "See the npm package") | ||
This method is like `_.assign` except that it iterates over own and | ||
inherited source properties. | ||
<br> | ||
<br> | ||
**Note:** This method mutates `object`. | ||
#### Aliases | ||
*_.extend* | ||
#### Arguments | ||
1. `object` *(Object)*: The destination object. | ||
2. `[sources]` *(...Object)*: The source objects. | ||
#### Returns | ||
*(Object)*: Returns `object`. | ||
#### Example | ||
```js | ||
function Foo() { | ||
this.b = 2; | ||
} | ||
function Bar() { | ||
this.d = 4; | ||
} | ||
Foo.prototype.c = 3; | ||
Bar.prototype.e = 5; | ||
_.assignIn({ 'a': 1 }, new Foo, new Bar); | ||
// => { 'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5 } | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_assigninwithobject-sources-customizer"></a>`_.assignInWith(object, s | ||
ources, [customizer])` | ||
<a href="#_assigninwithobject-sources-customizer">#</a> [Ⓢ](https://githu | ||
b.com/lodash/lodash/blob/4.0.0/lodash.js#L10433 "View in source") [Ⓣ][1] | ||
[Ⓝ](https://www.npmjs.com/package/lodash.assigninwith "See the npm packag | ||
e") | ||
This method is like `_.assignIn` except that it accepts `customizer` which | ||
is invoked to produce the assigned values. If `customizer` returns `undefined` | ||
assignment is handled by the method instead. The `customizer` is invoked | ||
with five arguments: (objValue, srcValue, key, object, source). | ||
<br> | ||
<br> | ||
**Note:** This method mutates `object`. | ||
#### Aliases | ||
*_.extendWith* | ||
#### Arguments | ||
1. `object` *(Object)*: The destination object. | ||
2. `sources` *(...Object)*: The source objects. | ||
3. `[customizer]` *(Function)*: The function to customize assigned values. | ||
#### Returns | ||
*(Object)*: Returns `object`. | ||
#### Example | ||
```js | ||
function customizer(objValue, srcValue) { | ||
return _.isUndefined(objValue) ? srcValue : objValue; | ||
} | ||
var defaults = _.partialRight(_.assignInWith, customizer); | ||
defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); | ||
// => { 'a': 1, 'b': 2 } | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_assignwithobject-sources-customizer"></a>`_.assignWith(object, sourc | ||
es, [customizer])` | ||
<a href="#_assignwithobject-sources-customizer">#</a> [Ⓢ](https://github. | ||
com/lodash/lodash/blob/4.0.0/lodash.js#L10463 "View in source") [Ⓣ][1] [& | ||
#x24C3;](https://www.npmjs.com/package/lodash.assignwith "See the npm package") | ||
This method is like `_.assign` except that it accepts `customizer` which | ||
is invoked to produce the assigned values. If `customizer` returns `undefined` | ||
assignment is handled by the method instead. The `customizer` is invoked | ||
with five arguments: (objValue, srcValue, key, object, source). | ||
<br> | ||
<br> | ||
**Note:** This method mutates `object`. | ||
#### Arguments | ||
1. `object` *(Object)*: The destination object. | ||
2. `sources` *(...Object)*: The source objects. | ||
3. `[customizer]` *(Function)*: The function to customize assigned values. | ||
#### Returns | ||
*(Object)*: Returns `object`. | ||
#### Example | ||
```js | ||
function customizer(objValue, srcValue) { | ||
return _.isUndefined(objValue) ? srcValue : objValue; | ||
} | ||
var defaults = _.partialRight(_.assignWith, customizer); | ||
defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); | ||
// => { 'a': 1, 'b': 2 } | ||
``` | ||
* * * | ||
<!-- /div --> | ||
<!-- div --> | ||
### <a id="_atobject-paths"></a>`_.at(object, [paths])` | ||
<a href="#_atobject-paths">#</a> [Ⓢ](https://github.com/lodash/lodash/blo | ||
b/4.0.0/lodash.js#L10487 "View in source") [Ⓣ][1] [Ⓝ](https://www. | ||
npmjs.com/package/lodash.at "See the npm package") | ||
Creates an array of values corresponding to `paths` of `object`. | ||
#### Arguments | ||
1. `object` *(Object)*: The object to iterate over. | ||
2. `[paths]` *(...(string|string[])*: The property paths of elements to | ||
pick, specified individually or in arrays. | ||
#### Returns | ||
*(Array)*: Returns the new array of picked elements. | ||
#### Example | ||
```js | ||
var object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; | ||
_.at(object, ['a[0].b.c', 'a[1]']); | ||
// => [3, 4] | ||
_.at(['a', 'b', 'c'], 0, 2); | ||
// => ['a', 'c'] | ||
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_createprototype-properties"></a>`_.create(prototype, [properties])` | ### <a id="_createprototype-properties"></a>`_.create(prototype, [properties])` | |
<a href="#_createprototype-properties">#</a> [Ⓢ](https://github.com/lodas h/lodash/blob/3.0.0/lodash.src.js#L8410 "View in source") [Ⓣ][1] | <a href="#_createprototype-properties">#</a> [Ⓢ](https://github.com/lodas h/lodash/blob/4.0.0/lodash.js#L10523 "View in source") [Ⓣ][1] [Ⓝ]( https://www.npmjs.com/package/lodash.create "See the npm package") | |
Creates an object that inherits from the given `prototype` object. If a | Creates an object that inherits from the `prototype` object. If a `properties` | |
`properties` object is provided its own enumerable properties are assigned | object is provided its own enumerable properties are assigned to the created obj | |
to the created object. | ect. | |
#### Arguments | #### Arguments | |
1. `prototype` *(Object)*: The object to inherit from. | 1. `prototype` *(Object)*: The object to inherit from. | |
2. `[properties]` *(Object)*: The properties to assign to the object. | 2. `[properties]` *(Object)*: The properties to assign to the object. | |
#### Returns | #### Returns | |
*(Object)*: Returns the new object. | *(Object)*: Returns the new object. | |
#### Example | #### Example | |
```js | ```js | |
function Shape() { | function Shape() { | |
this.x = 0; | this.x = 0; | |
this.y = 0; | this.y = 0; | |
} | } | |
function Circle() { | function Circle() { | |
Shape.call(this); | Shape.call(this); | |
} | } | |
Circle.prototype = _.create(Shape.prototype, { 'constructor': Circle }); | Circle.prototype = _.create(Shape.prototype, { | |
'constructor': Circle | ||
}); | ||
var circle = new Circle; | var circle = new Circle; | |
circle instanceof Circle; | circle instanceof Circle; | |
// => true | // => true | |
circle instanceof Shape; | circle instanceof Shape; | |
// => true | // => true | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_defaultsobject-sources"></a>`_.defaults(object, [sources])` | ### <a id="_defaultsobject-sources"></a>`_.defaults(object, [sources])` | |
<a href="#_defaultsobject-sources">#</a> [Ⓢ](https://github.com/lodash/lo dash/blob/3.0.0/lodash.src.js#L8434 "View in source") [Ⓣ][1] | <a href="#_defaultsobject-sources">#</a> [Ⓢ](https://github.com/lodash/lo dash/blob/4.0.0/lodash.js#L10547 "View in source") [Ⓣ][1] [Ⓝ](http s://www.npmjs.com/package/lodash.defaults "See the npm package") | |
Assigns own enumerable properties of source object(s) to the destination | Assigns own and inherited enumerable properties of source objects to the | |
object for all destination properties that resolve to `undefined`. Once a | destination object for all destination properties that resolve to `undefined`. | |
property is set, additional defaults of the same property are ignored. | Source objects are applied from left to right. Once a property is set, | |
additional values of the same property are ignored. | ||
<br> | ||
<br> | ||
**Note:** This method mutates `object`. | ||
#### Arguments | #### Arguments | |
1. `object` *(Object)*: The destination object. | 1. `object` *(Object)*: The destination object. | |
2. `[sources]` *(...Object)*: The source objects. | 2. `[sources]` *(...Object)*: The source objects. | |
#### Returns | #### Returns | |
*(Object)*: Returns `object`. | *(Object)*: Returns `object`. | |
#### Example | #### Example | |
```js | ```js | |
_.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' }); | _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' }); | |
// => { 'user': 'barney', 'age': 36 } | // => { 'user': 'barney', 'age': 36 } | |
``` | ``` | |
* * * | * * * | |
<!-- /div --> | <!-- /div --> | |
<!-- div --> | <!-- div --> | |
### <a id="_findkeyobject-predicate_identity-thisarg"></a>`_.findKey(object, [pr | ### <a id="_defaultsdeepobject-sources"></a>`_.defaultsDeep(object, [sources])` | |
edicate=_.identity], [thisArg])` | <a href="#_defaultsdeepobject-sources">#</a> [Ⓢ](https://github.com/lodas | |
<a href="#_findkeyobject-predicate_identity-thisarg">#</a> [Ⓢ](https://gi | h/lodash/blob/4.0.0/lodash.js#L10570 "View in source") [Ⓣ][1] [Ⓝ]( | |
thub.com/lodash/lodash/blob/3.0.0/lodash.src.js#L8482 "View in source") [Ⓣ | https://www.npmjs.com/package/lodash.defaultsdeep "See the npm package") | |
;][1] | ||
This method is like `_.defaults` except that it recursively assigns | ||
default properties. | ||
<br> | ||
<br> | ||
**Note:** This method mutates `object`. | ||
#### Arguments | ||
1. `object` *(Object)*: The destination object. | ||
2. `[sources]` *(...Object)*: The source objects. | ||
#### Returns | ||
*(Object)*: Returns `object`. | ||
#### Example | ||
```js | ||
_.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'ag | ||