mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-31 15:27:50 +00:00
8037 lines
237 KiB
Markdown
8037 lines
237 KiB
Markdown
# <a href="https://lodash.com/">lodash</a> <span>v3.10.1</span>
|
|
|
|
<!-- div class="toc-container" -->
|
|
|
|
<!-- div -->
|
|
|
|
## `Array`
|
|
* <a href="#_chunkarray-size1">`_.chunk`</a>
|
|
* <a href="#_compactarray">`_.compact`</a>
|
|
* <a href="#_differencearray-values">`_.difference`</a>
|
|
* <a href="#_droparray-n1">`_.drop`</a>
|
|
* <a href="#_droprightarray-n1">`_.dropRight`</a>
|
|
* <a href="#_droprightwhilearray-predicate_identity-thisarg">`_.dropRightWhile`</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="#_findlastindexarray-predicate_identity-thisarg">`_.findLastIndex`</a>
|
|
* <a href="#_firstarray">`_.first`</a>
|
|
* <a href="#_flattenarray-isdeep">`_.flatten`</a>
|
|
* <a href="#_flattendeeparray">`_.flattenDeep`</a>
|
|
* <a href="#_firstarray" class="alias">`_.head` -> `first`</a>
|
|
* <a href="#_indexofarray-value-fromindex0">`_.indexOf`</a>
|
|
* <a href="#_initialarray">`_.initial`</a>
|
|
* <a href="#_intersectionarrays">`_.intersection`</a>
|
|
* <a href="#_lastarray">`_.last`</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="#_pullatarray-indexes">`_.pullAt`</a>
|
|
* <a href="#_removearray-predicate_identity-thisarg">`_.remove`</a>
|
|
* <a href="#_restarray">`_.rest`</a>
|
|
* <a href="#_slicearray-start0-endarraylength">`_.slice`</a>
|
|
* <a href="#_sortedindexarray-value-iteratee_identity-thisarg">`_.sortedIndex`</a>
|
|
* <a href="#_sortedlastindexarray-value-iteratee_identity-thisarg">`_.sortedLastIndex`</a>
|
|
* <a href="#_restarray" class="alias">`_.tail` -> `rest`</a>
|
|
* <a href="#_takearray-n1">`_.take`</a>
|
|
* <a href="#_takerightarray-n1">`_.takeRight`</a>
|
|
* <a href="#_takerightwhilearray-predicate_identity-thisarg">`_.takeRightWhile`</a>
|
|
* <a href="#_takewhilearray-predicate_identity-thisarg">`_.takeWhile`</a>
|
|
* <a href="#_unionarrays">`_.union`</a>
|
|
* <a href="#_uniqarray-issorted-iteratee-thisarg">`_.uniq`</a>
|
|
* <a href="#_uniqarray-issorted-iteratee-thisarg" class="alias">`_.unique` -> `uniq`</a>
|
|
* <a href="#_unziparray">`_.unzip`</a>
|
|
* <a href="#_unzipwitharray-iteratee-thisarg">`_.unzipWith`</a>
|
|
* <a href="#_withoutarray-values">`_.without`</a>
|
|
* <a href="#_xorarrays">`_.xor`</a>
|
|
* <a href="#_ziparrays">`_.zip`</a>
|
|
* <a href="#_zipobjectprops-values">`_.zipObject`</a>
|
|
* <a href="#_zipwitharrays-iteratee-thisarg">`_.zipWith`</a>
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `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="#_prototypecommit">`_.prototype.commit`</a>
|
|
* <a href="#_prototypeconcatvalues">`_.prototype.concat`</a>
|
|
* <a href="#_prototypeplant">`_.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="#_prototypetostring">`_.prototype.toString`</a>
|
|
* <a href="#_prototypevalue">`_.prototype.value`</a>
|
|
* <a href="#_prototypevalue" class="alias">`_.prototype.valueOf` -> `value`</a>
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `Collection`
|
|
* <a href="#_everycollection-predicate_identity-thisarg" class="alias">`_.all` -> `every`</a>
|
|
* <a href="#_somecollection-predicate_identity-thisarg" class="alias">`_.any` -> `some`</a>
|
|
* <a href="#_atcollection-props">`_.at`</a>
|
|
* <a href="#_mapcollection-iteratee_identity-thisarg" class="alias">`_.collect` -> `map`</a>
|
|
* <a href="#_includescollection-target-fromindex0" class="alias">`_.contains` -> `includes`</a>
|
|
* <a href="#_countbycollection-iteratee_identity-thisarg">`_.countBy`</a>
|
|
* <a href="#_findcollection-predicate_identity-thisarg" class="alias">`_.detect` -> `find`</a>
|
|
* <a href="#_foreachcollection-iteratee_identity-thisarg" class="alias">`_.each` -> `forEach`</a>
|
|
* <a href="#_foreachrightcollection-iteratee_identity-thisarg" class="alias">`_.eachRight` -> `forEachRight`</a>
|
|
* <a href="#_everycollection-predicate_identity-thisarg">`_.every`</a>
|
|
* <a href="#_filtercollection-predicate_identity-thisarg">`_.filter`</a>
|
|
* <a href="#_findcollection-predicate_identity-thisarg">`_.find`</a>
|
|
* <a href="#_findlastcollection-predicate_identity-thisarg">`_.findLast`</a>
|
|
* <a href="#_findwherecollection-source">`_.findWhere`</a>
|
|
* <a href="#_reducecollection-iteratee_identity-accumulator-thisarg" class="alias">`_.foldl` -> `reduce`</a>
|
|
* <a href="#_reducerightcollection-iteratee_identity-accumulator-thisarg" class="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="alias">`_.inject` -> `reduce`</a>
|
|
* <a href="#_invokecollection-path-args">`_.invoke`</a>
|
|
* <a href="#_mapcollection-iteratee_identity-thisarg">`_.map`</a>
|
|
* <a href="#_partitioncollection-predicate_identity-thisarg">`_.partition`</a>
|
|
* <a href="#_pluckcollection-path">`_.pluck`</a>
|
|
* <a href="#_reducecollection-iteratee_identity-accumulator-thisarg">`_.reduce`</a>
|
|
* <a href="#_reducerightcollection-iteratee_identity-accumulator-thisarg">`_.reduceRight`</a>
|
|
* <a href="#_rejectcollection-predicate_identity-thisarg">`_.reject`</a>
|
|
* <a href="#_samplecollection-n">`_.sample`</a>
|
|
* <a href="#_filtercollection-predicate_identity-thisarg" class="alias">`_.select` -> `filter`</a>
|
|
* <a href="#_shufflecollection">`_.shuffle`</a>
|
|
* <a href="#_sizecollection">`_.size`</a>
|
|
* <a href="#_somecollection-predicate_identity-thisarg">`_.some`</a>
|
|
* <a href="#_sortbycollection-iteratee_identity-thisarg">`_.sortBy`</a>
|
|
* <a href="#_sortbyallcollection-iteratees">`_.sortByAll`</a>
|
|
* <a href="#_sortbyordercollection-iteratees-orders">`_.sortByOrder`</a>
|
|
* <a href="#_wherecollection-source">`_.where`</a>
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `Date`
|
|
* <a href="#_now">`_.now`</a>
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `Function`
|
|
* <a href="#_aftern-func">`_.after`</a>
|
|
* <a href="#_aryfunc-nfunclength">`_.ary`</a>
|
|
* <a href="#_flowrightfuncs" class="alias">`_.backflow` -> `flowRight`</a>
|
|
* <a href="#_beforen-func">`_.before`</a>
|
|
* <a href="#_bindfunc-thisarg-partials">`_.bind`</a>
|
|
* <a href="#_bindallobject-methodnames">`_.bindAll`</a>
|
|
* <a href="#_bindkeyobject-key-partials">`_.bindKey`</a>
|
|
* <a href="#_flowrightfuncs" class="alias">`_.compose` -> `flowRight`</a>
|
|
* <a href="#_curryfunc-arityfunclength">`_.curry`</a>
|
|
* <a href="#_curryrightfunc-arityfunclength">`_.curryRight`</a>
|
|
* <a href="#_debouncefunc-wait0-options">`_.debounce`</a>
|
|
* <a href="#_deferfunc-args">`_.defer`</a>
|
|
* <a href="#_delayfunc-wait-args">`_.delay`</a>
|
|
* <a href="#_flowfuncs">`_.flow`</a>
|
|
* <a href="#_flowrightfuncs">`_.flowRight`</a>
|
|
* <a href="#_memoizefunc-resolver">`_.memoize`</a>
|
|
* <a href="#_modargsfunc-transforms">`_.modArgs`</a>
|
|
* <a href="#_negatepredicate">`_.negate`</a>
|
|
* <a href="#_oncefunc">`_.once`</a>
|
|
* <a href="#_partialfunc-partials">`_.partial`</a>
|
|
* <a href="#_partialrightfunc-partials">`_.partialRight`</a>
|
|
* <a href="#_reargfunc-indexes">`_.rearg`</a>
|
|
* <a href="#_restparamfunc-startfunclength-1">`_.restParam`</a>
|
|
* <a href="#_spreadfunc">`_.spread`</a>
|
|
* <a href="#_throttlefunc-wait0-options">`_.throttle`</a>
|
|
* <a href="#_wrapvalue-wrapper">`_.wrap`</a>
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `Lang`
|
|
* <a href="#_clonevalue-isdeep-customizer-thisarg">`_.clone`</a>
|
|
* <a href="#_clonedeepvalue-customizer-thisarg">`_.cloneDeep`</a>
|
|
* <a href="#_isequalvalue-other-customizer-thisarg" class="alias">`_.eq` -> `isEqual`</a>
|
|
* <a href="#_gtvalue-other">`_.gt`</a>
|
|
* <a href="#_gtevalue-other">`_.gte`</a>
|
|
* <a href="#_isargumentsvalue">`_.isArguments`</a>
|
|
* <a href="#_isarrayvalue">`_.isArray`</a>
|
|
* <a href="#_isbooleanvalue">`_.isBoolean`</a>
|
|
* <a href="#_isdatevalue">`_.isDate`</a>
|
|
* <a href="#_iselementvalue">`_.isElement`</a>
|
|
* <a href="#_isemptyvalue">`_.isEmpty`</a>
|
|
* <a href="#_isequalvalue-other-customizer-thisarg">`_.isEqual`</a>
|
|
* <a href="#_iserrorvalue">`_.isError`</a>
|
|
* <a href="#_isfinitevalue">`_.isFinite`</a>
|
|
* <a href="#_isfunctionvalue">`_.isFunction`</a>
|
|
* <a href="#_ismatchobject-source-customizer-thisarg">`_.isMatch`</a>
|
|
* <a href="#_isnanvalue">`_.isNaN`</a>
|
|
* <a href="#_isnativevalue">`_.isNative`</a>
|
|
* <a href="#_isnullvalue">`_.isNull`</a>
|
|
* <a href="#_isnumbervalue">`_.isNumber`</a>
|
|
* <a href="#_isobjectvalue">`_.isObject`</a>
|
|
* <a href="#_isplainobjectvalue">`_.isPlainObject`</a>
|
|
* <a href="#_isregexpvalue">`_.isRegExp`</a>
|
|
* <a href="#_isstringvalue">`_.isString`</a>
|
|
* <a href="#_istypedarrayvalue">`_.isTypedArray`</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="#_toplainobjectvalue">`_.toPlainObject`</a>
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `Math`
|
|
* <a href="#_addaugend-addend">`_.add`</a>
|
|
* <a href="#_ceiln-precision0">`_.ceil`</a>
|
|
* <a href="#_floorn-precision0">`_.floor`</a>
|
|
* <a href="#_maxcollection-iteratee-thisarg">`_.max`</a>
|
|
* <a href="#_mincollection-iteratee-thisarg">`_.min`</a>
|
|
* <a href="#_roundn-precision0">`_.round`</a>
|
|
* <a href="#_sumcollection-iteratee-thisarg">`_.sum`</a>
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `Number`
|
|
* <a href="#_inrangen-start0-end">`_.inRange`</a>
|
|
* <a href="#_randommin0-max1-floating">`_.random`</a>
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `Object`
|
|
* <a href="#_assignobject-sources-customizer-thisarg">`_.assign`</a>
|
|
* <a href="#_createprototype-properties">`_.create`</a>
|
|
* <a href="#_defaultsobject-sources">`_.defaults`</a>
|
|
* <a href="#_defaultsdeepobject-sources">`_.defaultsDeep`</a>
|
|
* <a href="#_assignobject-sources-customizer-thisarg" class="alias">`_.extend` -> `assign`</a>
|
|
* <a href="#_findkeyobject-predicate_identity-thisarg">`_.findKey`</a>
|
|
* <a href="#_findlastkeyobject-predicate_identity-thisarg">`_.findLastKey`</a>
|
|
* <a href="#_forinobject-iteratee_identity-thisarg">`_.forIn`</a>
|
|
* <a href="#_forinrightobject-iteratee_identity-thisarg">`_.forInRight`</a>
|
|
* <a href="#_forownobject-iteratee_identity-thisarg">`_.forOwn`</a>
|
|
* <a href="#_forownrightobject-iteratee_identity-thisarg">`_.forOwnRight`</a>
|
|
* <a href="#_functionsobject">`_.functions`</a>
|
|
* <a href="#_getobject-path-defaultvalue">`_.get`</a>
|
|
* <a href="#_hasobject-path">`_.has`</a>
|
|
* <a href="#_invertobject-multivalue">`_.invert`</a>
|
|
* <a href="#_keysobject">`_.keys`</a>
|
|
* <a href="#_keysinobject">`_.keysIn`</a>
|
|
* <a href="#_mapkeysobject-iteratee_identity-thisarg">`_.mapKeys`</a>
|
|
* <a href="#_mapvaluesobject-iteratee_identity-thisarg">`_.mapValues`</a>
|
|
* <a href="#_mergeobject-sources-customizer-thisarg">`_.merge`</a>
|
|
* <a href="#_functionsobject" class="alias">`_.methods` -> `functions`</a>
|
|
* <a href="#_omitobject-predicate-thisarg">`_.omit`</a>
|
|
* <a href="#_pairsobject">`_.pairs`</a>
|
|
* <a href="#_pickobject-predicate-thisarg">`_.pick`</a>
|
|
* <a href="#_resultobject-path-defaultvalue">`_.result`</a>
|
|
* <a href="#_setobject-path-value">`_.set`</a>
|
|
* <a href="#_transformobject-iteratee_identity-accumulator-thisarg">`_.transform`</a>
|
|
* <a href="#_valuesobject">`_.values`</a>
|
|
* <a href="#_valuesinobject">`_.valuesIn`</a>
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `String`
|
|
* <a href="#_camelcasestring">`_.camelCase`</a>
|
|
* <a href="#_capitalizestring">`_.capitalize`</a>
|
|
* <a href="#_deburrstring">`_.deburr`</a>
|
|
* <a href="#_endswithstring-target-positionstringlength">`_.endsWith`</a>
|
|
* <a href="#_escapestring">`_.escape`</a>
|
|
* <a href="#_escaperegexpstring">`_.escapeRegExp`</a>
|
|
* <a href="#_kebabcasestring">`_.kebabCase`</a>
|
|
* <a href="#_padstring-length0-chars">`_.pad`</a>
|
|
* <a href="#_padleftstring-length0-chars">`_.padLeft`</a>
|
|
* <a href="#_padrightstring-length0-chars">`_.padRight`</a>
|
|
* <a href="#_parseintstring-radix">`_.parseInt`</a>
|
|
* <a href="#_repeatstring-n0">`_.repeat`</a>
|
|
* <a href="#_snakecasestring">`_.snakeCase`</a>
|
|
* <a href="#_startcasestring">`_.startCase`</a>
|
|
* <a href="#_startswithstring-target-position0">`_.startsWith`</a>
|
|
* <a href="#_templatestring-options">`_.template`</a>
|
|
* <a href="#_trimstring-charswhitespace">`_.trim`</a>
|
|
* <a href="#_trimleftstring-charswhitespace">`_.trimLeft`</a>
|
|
* <a href="#_trimrightstring-charswhitespace">`_.trimRight`</a>
|
|
* <a href="#_truncstring-options-optionslength30-optionsomission-optionsseparator">`_.trunc`</a>
|
|
* <a href="#_unescapestring">`_.unescape`</a>
|
|
* <a href="#_wordsstring-pattern">`_.words`</a>
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `Utility`
|
|
* <a href="#_attemptfunc">`_.attempt`</a>
|
|
* <a href="#_callbackfunc_identity-thisarg">`_.callback`</a>
|
|
* <a href="#_constantvalue">`_.constant`</a>
|
|
* <a href="#_identityvalue">`_.identity`</a>
|
|
* <a href="#_callbackfunc_identity-thisarg" class="alias">`_.iteratee` -> `callback`</a>
|
|
* <a href="#_matchessource">`_.matches`</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="#_noop">`_.noop`</a>
|
|
* <a href="#_propertypath">`_.property`</a>
|
|
* <a href="#_propertyofobject">`_.propertyOf`</a>
|
|
* <a href="#_rangestart0-end-step1">`_.range`</a>
|
|
* <a href="#_runincontextcontextroot">`_.runInContext`</a>
|
|
* <a href="#_timesn-iteratee_identity-thisarg">`_.times`</a>
|
|
* <a href="#_uniqueidprefix">`_.uniqueId`</a>
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `Methods`
|
|
* <a href="#_templatesettingsimports_">`_.templateSettings.imports._`</a>
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `Properties`
|
|
* <a href="#_version">`_.VERSION`</a>
|
|
* <a href="#_support">`_.support`</a>
|
|
* <a href="#_supportenumerrorprops">`_.support.enumErrorProps`</a>
|
|
* <a href="#_supportenumprototypes">`_.support.enumPrototypes`</a>
|
|
* <a href="#_supportnonenumshadows">`_.support.nonEnumShadows`</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="#_templatesettingsescape">`_.templateSettings.escape`</a>
|
|
* <a href="#_templatesettingsevaluate">`_.templateSettings.evaluate`</a>
|
|
* <a href="#_templatesettingsimports">`_.templateSettings.imports`</a>
|
|
* <a href="#_templatesettingsinterpolate">`_.templateSettings.interpolate`</a>
|
|
* <a href="#_templatesettingsvariable">`_.templateSettings.variable`</a>
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div class="doc-container" -->
|
|
|
|
<!-- div -->
|
|
|
|
## `“Array” Methods`
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_chunkarray-size1"></a>`_.chunk(array, [size=1])`
|
|
<a href="#_chunkarray-size1">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L4624 "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`.
|
|
If `collection` can't be split evenly, the final chunk will be the remaining
|
|
elements.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to process.
|
|
2. `[size=1]` *(number)*: The length of each chunk.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array containing chunks.
|
|
|
|
#### Example
|
|
```js
|
|
_.chunk(['a', 'b', 'c', 'd'], 2);
|
|
// => [['a', 'b'], ['c', 'd']]
|
|
|
|
_.chunk(['a', 'b', 'c', 'd'], 3);
|
|
// => [['a', 'b', 'c'], ['d']]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_compactarray"></a>`_.compact(array)`
|
|
<a href="#_compactarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L4655 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.compact "See the npm package")
|
|
|
|
Creates an array with all falsey values removed. The values `false`, `null`,
|
|
`0`, `""`, `undefined`, and `NaN` are falsey.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to compact.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array of filtered values.
|
|
|
|
#### Example
|
|
```js
|
|
_.compact([0, 1, false, 2, '', 3]);
|
|
// => [1, 2, 3]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_differencearray-values"></a>`_.difference(array, [values])`
|
|
<a href="#_differencearray-values">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L4686 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.difference "See the npm package")
|
|
|
|
Creates an array of unique `array` values not included in the other
|
|
provided arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
|
for equality comparisons.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to inspect.
|
|
2. `[values]` *(...Array)*: The arrays of values to exclude.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array of filtered values.
|
|
|
|
#### Example
|
|
```js
|
|
_.difference([1, 2, 3], [4, 2]);
|
|
// => [1, 3]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_droparray-n1"></a>`_.drop(array, [n=1])`
|
|
<a href="#_droparray-n1">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L4716 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.drop "See the npm package")
|
|
|
|
Creates a slice of `array` with `n` elements dropped from the beginning.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to query.
|
|
2. `[n=1]` *(number)*: The number of elements to drop.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the slice of `array`.
|
|
|
|
#### Example
|
|
```js
|
|
_.drop([1, 2, 3]);
|
|
// => [2, 3]
|
|
|
|
_.drop([1, 2, 3], 2);
|
|
// => [3]
|
|
|
|
_.drop([1, 2, 3], 5);
|
|
// => []
|
|
|
|
_.drop([1, 2, 3], 0);
|
|
// => [1, 2, 3]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_droprightarray-n1"></a>`_.dropRight(array, [n=1])`
|
|
<a href="#_droprightarray-n1">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L4751 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.dropright "See the npm package")
|
|
|
|
Creates a slice of `array` with `n` elements dropped from the end.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to query.
|
|
2. `[n=1]` *(number)*: The number of elements to drop.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the slice of `array`.
|
|
|
|
#### Example
|
|
```js
|
|
_.dropRight([1, 2, 3]);
|
|
// => [1, 2]
|
|
|
|
_.dropRight([1, 2, 3], 2);
|
|
// => [1]
|
|
|
|
_.dropRight([1, 2, 3], 5);
|
|
// => []
|
|
|
|
_.dropRight([1, 2, 3], 0);
|
|
// => [1, 2, 3]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_droprightwhilearray-predicate_identity-thisarg"></a>`_.dropRightWhile(array, [predicate=_.identity], [thisArg])`
|
|
<a href="#_droprightwhilearray-predicate_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L4812 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.droprightwhile "See the npm package")
|
|
|
|
Creates a slice of `array` excluding elements dropped from the end.
|
|
Elements are dropped until `predicate` returns falsey. The predicate is
|
|
bound to `thisArg` and invoked with three arguments: (value, index, array).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `predicate` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
If an object is provided for `predicate` the created `_.matches` style
|
|
callback returns `true` for elements that match the properties of the given
|
|
object, else `false`.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to query.
|
|
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the slice of `array`.
|
|
|
|
#### Example
|
|
```js
|
|
_.dropRightWhile([1, 2, 3], function(n) {
|
|
return n > 1;
|
|
});
|
|
// => [1]
|
|
|
|
var users = [
|
|
{ 'user': 'barney', 'active': true },
|
|
{ 'user': 'fred', 'active': false },
|
|
{ 'user': 'pebbles', 'active': false }
|
|
];
|
|
|
|
// using the `_.matches` callback shorthand
|
|
_.pluck(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
|
|
// => ['barney', 'fred']
|
|
|
|
// using the `_.matchesProperty` callback shorthand
|
|
_.pluck(_.dropRightWhile(users, 'active', false), 'user');
|
|
// => ['barney']
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.pluck(_.dropRightWhile(users, 'active'), 'user');
|
|
// => ['barney', 'fred', 'pebbles']
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_dropwhilearray-predicate_identity-thisarg"></a>`_.dropWhile(array, [predicate=_.identity], [thisArg])`
|
|
<a href="#_dropwhilearray-predicate_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L4867 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.dropwhile "See the npm package")
|
|
|
|
Creates a slice of `array` excluding elements dropped from the beginning.
|
|
Elements are dropped until `predicate` returns falsey. The predicate is
|
|
bound to `thisArg` and invoked with three arguments: (value, index, array).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `predicate` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
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. `array` *(Array)*: The array to query.
|
|
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the slice of `array`.
|
|
|
|
#### Example
|
|
```js
|
|
_.dropWhile([1, 2, 3], function(n) {
|
|
return n < 3;
|
|
});
|
|
// => [3]
|
|
|
|
var users = [
|
|
{ 'user': 'barney', 'active': false },
|
|
{ 'user': 'fred', 'active': false },
|
|
{ 'user': 'pebbles', 'active': true }
|
|
];
|
|
|
|
// using the `_.matches` callback shorthand
|
|
_.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
|
|
// => ['fred', 'pebbles']
|
|
|
|
// using the `_.matchesProperty` callback shorthand
|
|
_.pluck(_.dropWhile(users, 'active', false), 'user');
|
|
// => ['pebbles']
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.pluck(_.dropWhile(users, 'active'), 'user');
|
|
// => ['barney', 'fred', 'pebbles']
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_fillarray-value-start0-endarraylength"></a>`_.fill(array, value, [start=0], [end=array.length])`
|
|
<a href="#_fillarray-value-start0-endarraylength">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L4901 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.fill "See the npm package")
|
|
|
|
Fills elements of `array` with `value` from `start` up to, but not
|
|
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], '*', 1, 2);
|
|
// => [4, '*', 8]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_findindexarray-predicate_identity-thisarg"></a>`_.findIndex(array, [predicate=_.identity], [thisArg])`
|
|
<a href="#_findindexarray-predicate_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L4961 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.findindex "See the npm package")
|
|
|
|
This method is like `_.find` except that it returns the index of the first
|
|
element `predicate` returns truthy for instead of the element itself.
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `predicate` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
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. `array` *(Array)*: The array to search.
|
|
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(number)*: Returns the index of the found element, else `-1`.
|
|
|
|
#### Example
|
|
```js
|
|
var users = [
|
|
{ 'user': 'barney', 'active': false },
|
|
{ 'user': 'fred', 'active': false },
|
|
{ 'user': 'pebbles', 'active': true }
|
|
];
|
|
|
|
_.findIndex(users, function(chr) {
|
|
return chr.user == 'barney';
|
|
});
|
|
// => 0
|
|
|
|
// using the `_.matches` callback shorthand
|
|
_.findIndex(users, { 'user': 'fred', 'active': false });
|
|
// => 1
|
|
|
|
// using the `_.matchesProperty` callback shorthand
|
|
_.findIndex(users, 'active', false);
|
|
// => 0
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.findIndex(users, 'active');
|
|
// => 2
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_findlastindexarray-predicate_identity-thisarg"></a>`_.findLastIndex(array, [predicate=_.identity], [thisArg])`
|
|
<a href="#_findlastindexarray-predicate_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5011 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.findlastindex "See the npm package")
|
|
|
|
This method is like `_.findIndex` except that it iterates over elements
|
|
of `collection` from right to left.
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `predicate` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
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. `array` *(Array)*: The array to search.
|
|
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(number)*: Returns the index of the found element, else `-1`.
|
|
|
|
#### Example
|
|
```js
|
|
var users = [
|
|
{ 'user': 'barney', 'active': true },
|
|
{ 'user': 'fred', 'active': false },
|
|
{ 'user': 'pebbles', 'active': false }
|
|
];
|
|
|
|
_.findLastIndex(users, function(chr) {
|
|
return chr.user == 'pebbles';
|
|
});
|
|
// => 2
|
|
|
|
// using the `_.matches` callback shorthand
|
|
_.findLastIndex(users, { 'user': 'barney', 'active': true });
|
|
// => 0
|
|
|
|
// using the `_.matchesProperty` callback shorthand
|
|
_.findLastIndex(users, 'active', false);
|
|
// => 2
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.findLastIndex(users, 'active');
|
|
// => 0
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_firstarray"></a>`_.first(array)`
|
|
<a href="#_firstarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5030 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.first "See the npm package")
|
|
|
|
Gets the first element of `array`.
|
|
|
|
#### Aliases
|
|
*_.head*
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to query.
|
|
|
|
#### Returns
|
|
*(*)*: Returns the first element of `array`.
|
|
|
|
#### Example
|
|
```js
|
|
_.first([1, 2, 3]);
|
|
// => 1
|
|
|
|
_.first([]);
|
|
// => undefined
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_flattenarray-isdeep"></a>`_.flatten(array, [isDeep])`
|
|
<a href="#_flattenarray-isdeep">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5054 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.flatten "See the npm package")
|
|
|
|
Flattens a nested array. If `isDeep` is `true` the array is recursively
|
|
flattened, otherwise it's only flattened a single level.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to flatten.
|
|
2. `[isDeep]` *(boolean)*: Specify a deep flatten.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new flattened array.
|
|
|
|
#### Example
|
|
```js
|
|
_.flatten([1, [2, 3, [4]]]);
|
|
// => [1, 2, 3, [4]]
|
|
|
|
// using `isDeep`
|
|
_.flatten([1, [2, 3, [4]]], true);
|
|
// => [1, 2, 3, 4]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_flattendeeparray"></a>`_.flattenDeep(array)`
|
|
<a href="#_flattendeeparray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5075 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.flattendeep "See the npm package")
|
|
|
|
Recursively flattens a nested array.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to recursively flatten.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new flattened array.
|
|
|
|
#### Example
|
|
```js
|
|
_.flattenDeep([1, [2, 3, [4]]]);
|
|
// => [1, 2, 3, 4]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_indexofarray-value-fromindex0"></a>`_.indexOf(array, value, [fromIndex=0])`
|
|
<a href="#_indexofarray-value-fromindex0">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5108 "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`
|
|
using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
|
for equality comparisons. If `fromIndex` is negative, it's used as the offset
|
|
from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
|
|
performs a faster binary search.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to search.
|
|
2. `value` *(*)*: The value to search for.
|
|
3. `[fromIndex=0]` *(boolean|number)*: The index to search from or `true` to perform a binary search on a sorted array.
|
|
|
|
#### Returns
|
|
*(number)*: Returns the index of the matched value, else `-1`.
|
|
|
|
#### Example
|
|
```js
|
|
_.indexOf([1, 2, 1, 2], 2);
|
|
// => 1
|
|
|
|
// using `fromIndex`
|
|
_.indexOf([1, 2, 1, 2], 2, 2);
|
|
// => 3
|
|
|
|
// performing a binary search
|
|
_.indexOf([1, 1, 2, 2], 2, true);
|
|
// => 2
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_initialarray"></a>`_.initial(array)`
|
|
<a href="#_initialarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5139 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.initial "See the npm package")
|
|
|
|
Gets all but the last element of `array`.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to query.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the slice of `array`.
|
|
|
|
#### Example
|
|
```js
|
|
_.initial([1, 2, 3]);
|
|
// => [1, 2]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_intersectionarrays"></a>`_.intersection([arrays])`
|
|
<a href="#_intersectionarrays">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5157 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.intersection "See the npm package")
|
|
|
|
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-samevaluezero)
|
|
for equality comparisons.
|
|
|
|
#### Arguments
|
|
1. `[arrays]` *(...Array)*: The arrays to inspect.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array of shared values.
|
|
|
|
#### Example
|
|
```js
|
|
_.intersection([1, 2], [4, 2], [2, 1]);
|
|
// => [2]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_lastarray"></a>`_.last(array)`
|
|
<a href="#_lastarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5207 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.last "See the npm package")
|
|
|
|
Gets the last element of `array`.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to query.
|
|
|
|
#### Returns
|
|
*(*)*: Returns the last element of `array`.
|
|
|
|
#### Example
|
|
```js
|
|
_.last([1, 2, 3]);
|
|
// => 3
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_lastindexofarray-value-fromindexarraylength-1"></a>`_.lastIndexOf(array, value, [fromIndex=array.length-1])`
|
|
<a href="#_lastindexofarray-value-fromindexarraylength-1">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5237 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.lastindexof "See the npm package")
|
|
|
|
This method is like `_.indexOf` except that it iterates over elements of
|
|
`array` from right to left.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to search.
|
|
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.
|
|
|
|
#### Returns
|
|
*(number)*: Returns the index of the matched value, else `-1`.
|
|
|
|
#### Example
|
|
```js
|
|
_.lastIndexOf([1, 2, 1, 2], 2);
|
|
// => 3
|
|
|
|
// using `fromIndex`
|
|
_.lastIndexOf([1, 2, 1, 2], 2, 2);
|
|
// => 1
|
|
|
|
// performing a binary search
|
|
_.lastIndexOf([1, 1, 2, 2], 2, true);
|
|
// => 3
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_pullarray-values"></a>`_.pull(array, [values])`
|
|
<a href="#_pullarray-values">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5285 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.pull "See the npm package")
|
|
|
|
Removes all provided values from `array` using
|
|
[`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
|
for equality comparisons.
|
|
<br>
|
|
<br>
|
|
**Note:** Unlike `_.without`, this method mutates `array`.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to modify.
|
|
2. `[values]` *(...*)*: The values to remove.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns `array`.
|
|
|
|
#### Example
|
|
```js
|
|
var array = [1, 2, 3, 1, 2, 3];
|
|
|
|
_.pull(array, 2, 3);
|
|
console.log(array);
|
|
// => [1, 1]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_pullatarray-indexes"></a>`_.pullAt(array, [indexes])`
|
|
<a href="#_pullatarray-indexes">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5332 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.pullat "See the npm package")
|
|
|
|
Removes elements from `array` corresponding to the given indexes and returns
|
|
an array of the removed elements. Indexes may be specified as an array of
|
|
indexes or as individual arguments.
|
|
<br>
|
|
<br>
|
|
**Note:** Unlike `_.at`, this method mutates `array`.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to modify.
|
|
2. `[indexes]` *(...(number|number[])*: The indexes of elements to remove, specified as individual indexes or arrays of indexes.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array of removed elements.
|
|
|
|
#### Example
|
|
```js
|
|
var array = [5, 10, 15, 20];
|
|
var evens = _.pullAt(array, 1, 3);
|
|
|
|
console.log(array);
|
|
// => [5, 15]
|
|
|
|
console.log(evens);
|
|
// => [10, 20]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_removearray-predicate_identity-thisarg"></a>`_.remove(array, [predicate=_.identity], [thisArg])`
|
|
<a href="#_removearray-predicate_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5379 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.remove "See the npm package")
|
|
|
|
Removes all elements from `array` that `predicate` returns truthy for
|
|
and returns an array of the removed elements. The predicate is bound to
|
|
`thisArg` and invoked with three arguments: (value, index, array).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `predicate` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
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`.
|
|
<br>
|
|
<br>
|
|
**Note:** Unlike `_.filter`, this method mutates `array`.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to modify.
|
|
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array of removed elements.
|
|
|
|
#### Example
|
|
```js
|
|
var array = [1, 2, 3, 4];
|
|
var evens = _.remove(array, function(n) {
|
|
return n % 2 == 0;
|
|
});
|
|
|
|
console.log(array);
|
|
// => [1, 3]
|
|
|
|
console.log(evens);
|
|
// => [2, 4]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_restarray"></a>`_.rest(array)`
|
|
<a href="#_restarray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5414 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.rest "See the npm package")
|
|
|
|
Gets all but the first element of `array`.
|
|
|
|
#### Aliases
|
|
*_.tail*
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to query.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the slice of `array`.
|
|
|
|
#### Example
|
|
```js
|
|
_.rest([1, 2, 3]);
|
|
// => [2, 3]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_slicearray-start0-endarraylength"></a>`_.slice(array, [start=0], [end=array.length])`
|
|
<a href="#_slicearray-start0-endarraylength">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5432 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.slice "See the npm package")
|
|
|
|
Creates a slice of `array` from `start` up to, but not including, `end`.
|
|
<br>
|
|
<br>
|
|
**Note:** This method is used instead of `Array#slice` to support node
|
|
lists in IE < 9 and to ensure dense arrays are returned.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to slice.
|
|
2. `[start=0]` *(number)*: The start position.
|
|
3. `[end=array.length]` *(number)*: The end position.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the slice of `array`.
|
|
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_sortedindexarray-value-iteratee_identity-thisarg"></a>`_.sortedIndex(array, value, [iteratee=_.identity], [thisArg])`
|
|
<a href="#_sortedindexarray-value-iteratee_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5492 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.sortedindex "See the npm package")
|
|
|
|
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
|
|
function is provided it's 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).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `iteratee` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
If an object is provided for `iteratee` the created `_.matches` style
|
|
callback returns `true` for elements that have the properties of the given
|
|
object, else `false`.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The sorted array to inspect.
|
|
2. `value` *(*)*: The value to evaluate.
|
|
3. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
4. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(number)*: Returns the index at which `value` should be inserted
|
|
into `array`.
|
|
|
|
#### Example
|
|
```js
|
|
_.sortedIndex([30, 50], 40);
|
|
// => 1
|
|
|
|
_.sortedIndex([4, 4, 5, 5], 5);
|
|
// => 2
|
|
|
|
var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
|
|
|
|
// using an iteratee function
|
|
_.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
|
|
return this.data[word];
|
|
}, dict);
|
|
// => 1
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
|
|
// => 1
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_sortedlastindexarray-value-iteratee_identity-thisarg"></a>`_.sortedLastIndex(array, value, [iteratee=_.identity], [thisArg])`
|
|
<a href="#_sortedlastindexarray-value-iteratee_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5514 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.sortedlastindex "See the npm package")
|
|
|
|
This method is like `_.sortedIndex` except that it returns the highest
|
|
index at which `value` should be inserted into `array` in order to
|
|
maintain its sort order.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The sorted array to inspect.
|
|
2. `value` *(*)*: The value to evaluate.
|
|
3. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
4. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(number)*: Returns the index at which `value` should be inserted
|
|
into `array`.
|
|
|
|
#### Example
|
|
```js
|
|
_.sortedLastIndex([4, 4, 5, 5], 5);
|
|
// => 4
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_takearray-n1"></a>`_.take(array, [n=1])`
|
|
<a href="#_takearray-n1">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5540 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.take "See the npm package")
|
|
|
|
Creates a slice of `array` with `n` elements taken from the beginning.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to query.
|
|
2. `[n=1]` *(number)*: The number of elements to take.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the slice of `array`.
|
|
|
|
#### Example
|
|
```js
|
|
_.take([1, 2, 3]);
|
|
// => [1]
|
|
|
|
_.take([1, 2, 3], 2);
|
|
// => [1, 2]
|
|
|
|
_.take([1, 2, 3], 5);
|
|
// => [1, 2, 3]
|
|
|
|
_.take([1, 2, 3], 0);
|
|
// => []
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_takerightarray-n1"></a>`_.takeRight(array, [n=1])`
|
|
<a href="#_takerightarray-n1">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5575 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.takeright "See the npm package")
|
|
|
|
Creates a slice of `array` with `n` elements taken from the end.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to query.
|
|
2. `[n=1]` *(number)*: The number of elements to take.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the slice of `array`.
|
|
|
|
#### Example
|
|
```js
|
|
_.takeRight([1, 2, 3]);
|
|
// => [3]
|
|
|
|
_.takeRight([1, 2, 3], 2);
|
|
// => [2, 3]
|
|
|
|
_.takeRight([1, 2, 3], 5);
|
|
// => [1, 2, 3]
|
|
|
|
_.takeRight([1, 2, 3], 0);
|
|
// => []
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_takerightwhilearray-predicate_identity-thisarg"></a>`_.takeRightWhile(array, [predicate=_.identity], [thisArg])`
|
|
<a href="#_takerightwhilearray-predicate_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5636 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.takerightwhile "See the npm package")
|
|
|
|
Creates a slice of `array` with elements taken from the end. Elements are
|
|
taken until `predicate` returns falsey. The predicate is bound to `thisArg`
|
|
and invoked with three arguments: (value, index, array).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `predicate` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
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. `array` *(Array)*: The array to query.
|
|
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the slice of `array`.
|
|
|
|
#### Example
|
|
```js
|
|
_.takeRightWhile([1, 2, 3], function(n) {
|
|
return n > 1;
|
|
});
|
|
// => [2, 3]
|
|
|
|
var users = [
|
|
{ 'user': 'barney', 'active': true },
|
|
{ 'user': 'fred', 'active': false },
|
|
{ 'user': 'pebbles', 'active': false }
|
|
];
|
|
|
|
// using the `_.matches` callback shorthand
|
|
_.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
|
|
// => ['pebbles']
|
|
|
|
// using the `_.matchesProperty` callback shorthand
|
|
_.pluck(_.takeRightWhile(users, 'active', false), 'user');
|
|
// => ['fred', 'pebbles']
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.pluck(_.takeRightWhile(users, 'active'), 'user');
|
|
// => []
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_takewhilearray-predicate_identity-thisarg"></a>`_.takeWhile(array, [predicate=_.identity], [thisArg])`
|
|
<a href="#_takewhilearray-predicate_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5691 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.takewhile "See the npm package")
|
|
|
|
Creates a slice of `array` with elements taken from the beginning. Elements
|
|
are taken until `predicate` returns falsey. The predicate is bound to
|
|
`thisArg` and invoked with three arguments: (value, index, array).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `predicate` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
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. `array` *(Array)*: The array to query.
|
|
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the slice of `array`.
|
|
|
|
#### Example
|
|
```js
|
|
_.takeWhile([1, 2, 3], function(n) {
|
|
return n < 3;
|
|
});
|
|
// => [1, 2]
|
|
|
|
var users = [
|
|
{ 'user': 'barney', 'active': false },
|
|
{ 'user': 'fred', 'active': false},
|
|
{ 'user': 'pebbles', 'active': true }
|
|
];
|
|
|
|
// using the `_.matches` callback shorthand
|
|
_.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
|
|
// => ['barney']
|
|
|
|
// using the `_.matchesProperty` callback shorthand
|
|
_.pluck(_.takeWhile(users, 'active', false), 'user');
|
|
// => ['barney', 'fred']
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.pluck(_.takeWhile(users, 'active'), 'user');
|
|
// => []
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_unionarrays"></a>`_.union([arrays])`
|
|
<a href="#_unionarrays">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5712 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.union "See the npm package")
|
|
|
|
Creates an array of unique values, in order, from all of the provided arrays
|
|
using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
|
for equality comparisons.
|
|
|
|
#### Arguments
|
|
1. `[arrays]` *(...Array)*: The arrays to inspect.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array of combined values.
|
|
|
|
#### Example
|
|
```js
|
|
_.union([1, 2], [4, 2], [2, 1]);
|
|
// => [1, 2, 4]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_uniqarray-issorted-iteratee-thisarg"></a>`_.uniq(array, [isSorted], [iteratee], [thisArg])`
|
|
<a href="#_uniqarray-issorted-iteratee-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5765 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.uniq "See the npm package")
|
|
|
|
Creates a duplicate-free version of an array, using
|
|
[`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
|
for equality comparisons, in which only the first occurence of each element
|
|
is kept. Providing `true` for `isSorted` performs a faster search algorithm
|
|
for sorted arrays. If an iteratee function is provided it's invoked for
|
|
each element 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).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `iteratee` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
If an object is provided for `iteratee` the created `_.matches` style
|
|
callback returns `true` for elements that have the properties of the given
|
|
object, else `false`.
|
|
|
|
#### Aliases
|
|
*_.unique*
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to inspect.
|
|
2. `[isSorted]` *(boolean)*: Specify the array is sorted.
|
|
3. `[iteratee]` *(Function|Object|string)*: The function invoked per iteration.
|
|
4. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new duplicate-value-free array.
|
|
|
|
#### Example
|
|
```js
|
|
_.uniq([2, 1, 2]);
|
|
// => [2, 1]
|
|
|
|
// using `isSorted`
|
|
_.uniq([1, 1, 2], true);
|
|
// => [1, 2]
|
|
|
|
// using an iteratee function
|
|
_.uniq([1, 2.5, 1.5, 2], function(n) {
|
|
return this.floor(n);
|
|
}, Math);
|
|
// => [1, 2.5]
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
|
|
// => [{ 'x': 1 }, { 'x': 2 }]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_unziparray"></a>`_.unzip(array)`
|
|
<a href="#_unziparray">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5802 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.unzip "See the npm package")
|
|
|
|
This method is like `_.zip` except that it accepts an array of grouped
|
|
elements and creates an array regrouping the elements to their pre-zip
|
|
configuration.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array of grouped elements to process.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array of regrouped elements.
|
|
|
|
#### Example
|
|
```js
|
|
var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
|
|
// => [['fred', 30, true], ['barney', 40, false]]
|
|
|
|
_.unzip(zipped);
|
|
// => [['fred', 'barney'], [30, 40], [true, false]]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_unzipwitharray-iteratee-thisarg"></a>`_.unzipWith(array, [iteratee], [thisArg])`
|
|
<a href="#_unzipwitharray-iteratee-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5842 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.unzipwith "See the npm package")
|
|
|
|
This method is like `_.unzip` except that it accepts an iteratee to specify
|
|
how regrouped values should be combined. The `iteratee` is bound to `thisArg`
|
|
and invoked with four arguments: (accumulator, value, index, group).
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array of grouped elements to process.
|
|
2. `[iteratee]` *(Function)*: The function to combine regrouped values.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array of regrouped elements.
|
|
|
|
#### Example
|
|
```js
|
|
var zipped = _.zip([1, 2], [10, 20], [100, 200]);
|
|
// => [[1, 10, 100], [2, 20, 200]]
|
|
|
|
_.unzipWith(zipped, _.add);
|
|
// => [3, 30, 300]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_withoutarray-values"></a>`_.without(array, [values])`
|
|
<a href="#_withoutarray-values">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5873 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.without "See the npm package")
|
|
|
|
Creates an array excluding all provided values using
|
|
[`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
|
for equality comparisons.
|
|
|
|
#### Arguments
|
|
1. `array` *(Array)*: The array to filter.
|
|
2. `[values]` *(...*)*: The values to exclude.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array of filtered values.
|
|
|
|
#### Example
|
|
```js
|
|
_.without([1, 2, 1, 3], 1, 2);
|
|
// => [3]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_xorarrays"></a>`_.xor([arrays])`
|
|
<a href="#_xorarrays">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5893 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.xor "See the npm package")
|
|
|
|
Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
|
|
of the provided arrays.
|
|
|
|
#### Arguments
|
|
1. `[arrays]` *(...Array)*: The arrays to inspect.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array of values.
|
|
|
|
#### Example
|
|
```js
|
|
_.xor([1, 2], [4, 2]);
|
|
// => [1, 4]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_ziparrays"></a>`_.zip([arrays])`
|
|
<a href="#_ziparrays">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5923 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.zip "See the npm package")
|
|
|
|
Creates an array of grouped elements, the first of which contains the first
|
|
elements of the given arrays, the second of which contains the second elements
|
|
of the given arrays, and so on.
|
|
|
|
#### Arguments
|
|
1. `[arrays]` *(...Array)*: The arrays to process.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array of grouped elements.
|
|
|
|
#### Example
|
|
```js
|
|
_.zip(['fred', 'barney'], [30, 40], [true, false]);
|
|
// => [['fred', 30, true], ['barney', 40, false]]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_zipobjectprops-values"></a>`_.zipObject(props, [values=[]])`
|
|
<a href="#_zipobjectprops-values">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5946 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.zipobject "See the npm package")
|
|
|
|
The inverse of `_.pairs`; this method returns an object composed from arrays
|
|
of property names and values. Provide either a single two dimensional array,
|
|
e.g. `[[key1, value1], [key2, value2]]` or two arrays, one of property names
|
|
and one of corresponding values.
|
|
|
|
#### Aliases
|
|
*_.object*
|
|
|
|
#### Arguments
|
|
1. `props` *(Array)*: The property names.
|
|
2. `[values=[]]` *(Array)*: The property values.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the new object.
|
|
|
|
#### Example
|
|
```js
|
|
_.zipObject([['fred', 30], ['barney', 40]]);
|
|
// => { 'fred': 30, 'barney': 40 }
|
|
|
|
_.zipObject(['fred', 'barney'], [30, 40]);
|
|
// => { 'fred': 30, 'barney': 40 }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_zipwitharrays-iteratee-thisarg"></a>`_.zipWith([arrays], [iteratee], [thisArg])`
|
|
<a href="#_zipwitharrays-iteratee-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L5982 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.zipwith "See the npm package")
|
|
|
|
This method is like `_.zip` except that it accepts an iteratee to specify
|
|
how grouped values should be combined. The `iteratee` is bound to `thisArg`
|
|
and invoked with four arguments: (accumulator, value, index, group).
|
|
|
|
#### Arguments
|
|
1. `[arrays]` *(...Array)*: The arrays to process.
|
|
2. `[iteratee]` *(Function)*: The function to combine grouped values.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array of grouped elements.
|
|
|
|
#### Example
|
|
```js
|
|
_.zipWith([1, 2], [10, 20], [100, 200], _.add);
|
|
// => [111, 222]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `“Chain” Methods`
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_value"></a>`_(value)`
|
|
<a href="#_value">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L944 "View in source") [Ⓣ][1]
|
|
|
|
Creates a `lodash` object which wraps `value` to enable implicit chaining.
|
|
Methods that operate on and return arrays, collections, and functions can
|
|
be chained together. Methods that retrieve a single value or may return a
|
|
primitive 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.
|
|
<br>
|
|
<br>
|
|
Lazy evaluation allows several methods to support shortcut fusion. Shortcut
|
|
fusion is an optimization strategy which merge iteratee calls; this can help
|
|
to avoid the creation of intermediate data structures and greatly reduce the
|
|
number of iteratee executions.
|
|
<br>
|
|
<br>
|
|
Chaining is supported in custom builds as long as the `_#value` method is
|
|
directly or indirectly included in the build.
|
|
<br>
|
|
<br>
|
|
In addition to lodash methods, wrappers have `Array` and `String` methods.
|
|
<br>
|
|
<br>
|
|
The wrapper `Array` methods are:<br>
|
|
`concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
|
|
`splice`, and `unshift`
|
|
<br>
|
|
<br>
|
|
The wrapper `String` methods are:<br>
|
|
`replace` and `split`
|
|
<br>
|
|
<br>
|
|
The wrapper methods that support shortcut fusion are:<br>
|
|
`compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
|
|
`first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
|
|
`slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
|
|
and `where`
|
|
<br>
|
|
<br>
|
|
The chainable wrapper methods are:<br>
|
|
`after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
|
|
`callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
|
|
`countBy`, `create`, `curry`, `debounce`, `defaults`, `defaultsDeep`,
|
|
`defer`, `delay`, `difference`, `drop`, `dropRight`, `dropRightWhile`,
|
|
`dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`,
|
|
`forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
|
|
`functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
|
|
`invoke`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`,
|
|
`matchesProperty`, `memoize`, `merge`, `method`, `methodOf`, `mixin`,
|
|
`modArgs`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
|
|
`partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
|
|
`pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `restParam`,
|
|
`reverse`, `set`, `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`,
|
|
`sortByOrder`, `splice`, `spread`, `take`, `takeRight`, `takeRightWhile`,
|
|
`takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
|
|
`transform`, `union`, `uniq`, `unshift`, `unzip`, `unzipWith`, `values`,
|
|
`valuesIn`, `where`, `without`, `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
|
|
<br>
|
|
<br>
|
|
The wrapper methods that are **not** chainable by default are:<br>
|
|
`add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
|
|
`deburr`, `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`,
|
|
`findKey`, `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`,
|
|
`floor`, `get`, `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`,
|
|
`inRange`, `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`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
|
|
`now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
|
|
`reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
|
|
`snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`,
|
|
`startsWith`, `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`,
|
|
`unescape`, `uniqueId`, `value`, and `words`
|
|
<br>
|
|
<br>
|
|
The wrapper method `sample` will return a wrapped value when `n` is provided,
|
|
otherwise an unwrapped value is returned.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to wrap in a `lodash` instance.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the new `lodash` wrapper instance.
|
|
|
|
#### Example
|
|
```js
|
|
var wrapped = _([1, 2, 3]);
|
|
|
|
// returns an unwrapped value
|
|
wrapped.reduce(function(total, n) {
|
|
return total + n;
|
|
});
|
|
// => 6
|
|
|
|
// returns a wrapped value
|
|
var squares = wrapped.map(function(n) {
|
|
return n * n;
|
|
});
|
|
|
|
_.isArray(squares);
|
|
// => false
|
|
|
|
_.isArray(squares.value());
|
|
// => true
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_chainvalue"></a>`_.chain(value)`
|
|
<a href="#_chainvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6025 "View in source") [Ⓣ][1]
|
|
|
|
Creates a `lodash` object that wraps `value` with explicit method
|
|
chaining enabled.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to wrap.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the new `lodash` wrapper instance.
|
|
|
|
#### Example
|
|
```js
|
|
var users = [
|
|
{ 'user': 'barney', 'age': 36 },
|
|
{ '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 -->
|
|
|
|
### <a id="_tapvalue-interceptor-thisarg"></a>`_.tap(value, interceptor, [thisArg])`
|
|
<a href="#_tapvalue-interceptor-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6054 "View in source") [Ⓣ][1]
|
|
|
|
This method invokes `interceptor` and returns `value`. The interceptor is
|
|
bound to `thisArg` and invoked with one argument; (value). The purpose of
|
|
this method is to "tap into" a method chain in order to perform operations
|
|
on intermediate results within the chain.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to provide to `interceptor`.
|
|
2. `interceptor` *(Function)*: The function to invoke.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `interceptor`.
|
|
|
|
#### Returns
|
|
*(*)*: Returns `value`.
|
|
|
|
#### Example
|
|
```js
|
|
_([1, 2, 3])
|
|
.tap(function(array) {
|
|
array.pop();
|
|
})
|
|
.reverse()
|
|
.value();
|
|
// => [2, 1]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_thruvalue-interceptor-thisarg"></a>`_.thru(value, interceptor, [thisArg])`
|
|
<a href="#_thruvalue-interceptor-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6080 "View in source") [Ⓣ][1]
|
|
|
|
This method is like `_.tap` except that it returns the result of `interceptor`.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to provide to `interceptor`.
|
|
2. `interceptor` *(Function)*: The function to invoke.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `interceptor`.
|
|
|
|
#### Returns
|
|
*(*)*: Returns the result of `interceptor`.
|
|
|
|
#### Example
|
|
```js
|
|
_(' abc ')
|
|
.chain()
|
|
.trim()
|
|
.thru(function(value) {
|
|
return [value];
|
|
})
|
|
.value();
|
|
// => ['abc']
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_prototypechain"></a>`_.prototype.chain()`
|
|
<a href="#_prototypechain">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6109 "View in source") [Ⓣ][1]
|
|
|
|
Enables explicit method chaining on the wrapper object.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the new `lodash` wrapper instance.
|
|
|
|
#### Example
|
|
```js
|
|
var users = [
|
|
{ 'user': 'barney', 'age': 36 },
|
|
{ 'user': 'fred', 'age': 40 }
|
|
];
|
|
|
|
// without explicit chaining
|
|
_(users).first();
|
|
// => { 'user': 'barney', 'age': 36 }
|
|
|
|
// with explicit chaining
|
|
_(users).chain()
|
|
.first()
|
|
.pick('user')
|
|
.value();
|
|
// => { 'user': 'barney' }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_prototypecommit"></a>`_.prototype.commit()`
|
|
<a href="#_prototypecommit">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6138 "View in source") [Ⓣ][1]
|
|
|
|
Executes the chained sequence and returns the wrapped result.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the new `lodash` wrapper instance.
|
|
|
|
#### Example
|
|
```js
|
|
var array = [1, 2];
|
|
var wrapped = _(array).push(3);
|
|
|
|
console.log(array);
|
|
// => [1, 2]
|
|
|
|
wrapped = wrapped.commit();
|
|
console.log(array);
|
|
// => [1, 2, 3]
|
|
|
|
wrapped.last();
|
|
// => 3
|
|
|
|
console.log(array);
|
|
// => [1, 2, 3]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_prototypeconcatvalues"></a>`_.prototype.concat([values])`
|
|
<a href="#_prototypeconcatvalues">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6162 "View in source") [Ⓣ][1]
|
|
|
|
Creates a new array joining a wrapped array with any additional arrays
|
|
and/or values.
|
|
|
|
#### Arguments
|
|
1. `[values]` *(...*)*: The values to concatenate.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new concatenated array.
|
|
|
|
#### Example
|
|
```js
|
|
var array = [1];
|
|
var wrapped = _(array).concat(2, [3], [[4]]);
|
|
|
|
console.log(wrapped.value());
|
|
// => [1, 2, 3, [4]]
|
|
|
|
console.log(array);
|
|
// => [1]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_prototypeplant"></a>`_.prototype.plant()`
|
|
<a href="#_prototypeplant">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6192 "View in source") [Ⓣ][1]
|
|
|
|
Creates a clone of the chained sequence planting `value` as the wrapped value.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the new `lodash` wrapper instance.
|
|
|
|
#### Example
|
|
```js
|
|
var array = [1, 2];
|
|
var wrapped = _(array).map(function(value) {
|
|
return Math.pow(value, 2);
|
|
});
|
|
|
|
var other = [3, 4];
|
|
var otherWrapped = wrapped.plant(other);
|
|
|
|
otherWrapped.value();
|
|
// => [9, 16]
|
|
|
|
wrapped.value();
|
|
// => [1, 4]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_prototypereverse"></a>`_.prototype.reverse()`
|
|
<a href="#_prototypereverse">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6230 "View in source") [Ⓣ][1]
|
|
|
|
Reverses the wrapped array so the first element becomes the last, the
|
|
second element becomes the second to last, and so on.
|
|
<br>
|
|
<br>
|
|
**Note:** This method mutates the wrapped array.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the new reversed `lodash` wrapper instance.
|
|
|
|
#### Example
|
|
```js
|
|
var array = [1, 2, 3];
|
|
|
|
_(array).reverse().value()
|
|
// => [3, 2, 1]
|
|
|
|
console.log(array);
|
|
// => [3, 2, 1]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_prototypetostring"></a>`_.prototype.toString()`
|
|
<a href="#_prototypetostring">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6260 "View in source") [Ⓣ][1]
|
|
|
|
Produces the result of coercing the unwrapped value to a string.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the coerced string value.
|
|
|
|
#### Example
|
|
```js
|
|
_([1, 2, 3]).toString();
|
|
// => '1,2,3'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_prototypevalue"></a>`_.prototype.value()`
|
|
<a href="#_prototypevalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6277 "View in source") [Ⓣ][1]
|
|
|
|
Executes the chained sequence to extract the unwrapped value.
|
|
|
|
#### Aliases
|
|
*_.prototype.run, _.prototype.toJSON, _.prototype.valueOf*
|
|
|
|
#### Returns
|
|
*(*)*: Returns the resolved unwrapped value.
|
|
|
|
#### Example
|
|
```js
|
|
_([1, 2, 3]).value();
|
|
// => [1, 2, 3]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `“Collection” Methods`
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_atcollection-props"></a>`_.at(collection, [props])`
|
|
<a href="#_atcollection-props">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6303 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.at "See the npm package")
|
|
|
|
Creates an array of elements corresponding to the given keys, or indexes,
|
|
of `collection`. Keys may be specified as individual arguments or as arrays
|
|
of keys.
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to iterate over.
|
|
2. `[props]` *(...(number|number[]|string|string[])*: The property names or indexes of elements to pick, specified individually or in arrays.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array of picked elements.
|
|
|
|
#### Example
|
|
```js
|
|
_.at(['a', 'b', 'c'], [0, 2]);
|
|
// => ['a', 'c']
|
|
|
|
_.at(['barney', 'fred', 'pebbles'], 0, 2);
|
|
// => ['barney', 'pebbles']
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_countbycollection-iteratee_identity-thisarg"></a>`_.countBy(collection, [iteratee=_.identity], [thisArg])`
|
|
<a href="#_countbycollection-iteratee_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6351 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.countby "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 number of times the key was returned by `iteratee`.
|
|
The `iteratee` is bound to `thisArg` and invoked with three arguments:<br>
|
|
(value, index|key, collection).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `iteratee` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
If an object is provided for `iteratee` 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=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the composed aggregate object.
|
|
|
|
#### Example
|
|
```js
|
|
_.countBy([4.3, 6.1, 6.4], function(n) {
|
|
return Math.floor(n);
|
|
});
|
|
// => { '4': 1, '6': 2 }
|
|
|
|
_.countBy([4.3, 6.1, 6.4], function(n) {
|
|
return this.floor(n);
|
|
}, Math);
|
|
// => { '4': 1, '6': 2 }
|
|
|
|
_.countBy(['one', 'two', 'three'], 'length');
|
|
// => { '3': 2, '5': 1 }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_everycollection-predicate_identity-thisarg"></a>`_.every(collection, [predicate=_.identity], [thisArg])`
|
|
<a href="#_everycollection-predicate_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6403 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.every "See the npm package")
|
|
|
|
Checks if `predicate` returns truthy for **all** elements of `collection`.
|
|
The predicate is bound to `thisArg` and invoked with three arguments:<br>
|
|
(value, index|key, collection).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `predicate` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
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`.
|
|
|
|
#### Aliases
|
|
*_.all*
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to iterate over.
|
|
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if all elements pass the predicate check,
|
|
else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.every([true, 1, null, 'yes'], Boolean);
|
|
// => false
|
|
|
|
var users = [
|
|
{ 'user': 'barney', 'active': false },
|
|
{ 'user': 'fred', 'active': false }
|
|
];
|
|
|
|
// using the `_.matches` callback shorthand
|
|
_.every(users, { 'user': 'barney', 'active': false });
|
|
// => false
|
|
|
|
// using the `_.matchesProperty` callback shorthand
|
|
_.every(users, 'active', false);
|
|
// => true
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.every(users, 'active');
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_filtercollection-predicate_identity-thisarg"></a>`_.filter(collection, [predicate=_.identity], [thisArg])`
|
|
<a href="#_filtercollection-predicate_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6463 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.filter "See the npm package")
|
|
|
|
Iterates over elements of `collection`, returning an array of all elements
|
|
`predicate` returns truthy for. The predicate is bound to `thisArg` and
|
|
invoked with three arguments: (value, index|key, collection).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `predicate` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
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`.
|
|
|
|
#### Aliases
|
|
*_.select*
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to iterate over.
|
|
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new filtered array.
|
|
|
|
#### Example
|
|
```js
|
|
_.filter([4, 5, 6], function(n) {
|
|
return n % 2 == 0;
|
|
});
|
|
// => [4, 6]
|
|
|
|
var users = [
|
|
{ 'user': 'barney', 'age': 36, 'active': true },
|
|
{ 'user': 'fred', 'age': 40, 'active': false }
|
|
];
|
|
|
|
// using the `_.matches` callback shorthand
|
|
_.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
|
|
// => ['barney']
|
|
|
|
// using the `_.matchesProperty` callback shorthand
|
|
_.pluck(_.filter(users, 'active', false), 'user');
|
|
// => ['fred']
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.pluck(_.filter(users, 'active'), 'user');
|
|
// => ['barney']
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_findcollection-predicate_identity-thisarg"></a>`_.find(collection, [predicate=_.identity], [thisArg])`
|
|
<a href="#_findcollection-predicate_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6519 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.find "See the npm package")
|
|
|
|
Iterates over elements of `collection`, returning the first element
|
|
`predicate` returns truthy for. The predicate is bound to `thisArg` and
|
|
invoked with three arguments: (value, index|key, collection).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `predicate` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
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`.
|
|
|
|
#### Aliases
|
|
*_.detect*
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to search.
|
|
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(*)*: Returns the matched element, else `undefined`.
|
|
|
|
#### Example
|
|
```js
|
|
var users = [
|
|
{ 'user': 'barney', 'age': 36, 'active': true },
|
|
{ 'user': 'fred', 'age': 40, 'active': false },
|
|
{ 'user': 'pebbles', 'age': 1, 'active': true }
|
|
];
|
|
|
|
_.result(_.find(users, function(chr) {
|
|
return chr.age < 40;
|
|
}), 'user');
|
|
// => 'barney'
|
|
|
|
// using the `_.matches` callback shorthand
|
|
_.result(_.find(users, { 'age': 1, 'active': true }), 'user');
|
|
// => 'pebbles'
|
|
|
|
// using the `_.matchesProperty` callback shorthand
|
|
_.result(_.find(users, 'active', false), 'user');
|
|
// => 'fred'
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.result(_.find(users, 'active'), 'user');
|
|
// => 'barney'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_findlastcollection-predicate_identity-thisarg"></a>`_.findLast(collection, [predicate=_.identity], [thisArg])`
|
|
<a href="#_findlastcollection-predicate_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6540 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.findlast "See the npm package")
|
|
|
|
This method is like `_.find` except that it iterates over elements of
|
|
`collection` from right to left.
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to search.
|
|
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(*)*: Returns the matched element, else `undefined`.
|
|
|
|
#### Example
|
|
```js
|
|
_.findLast([1, 2, 3, 4], function(n) {
|
|
return n % 2 == 1;
|
|
});
|
|
// => 3
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_findwherecollection-source"></a>`_.findWhere(collection, source)`
|
|
<a href="#_findwherecollection-source">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6571 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.findwhere "See the npm package")
|
|
|
|
Performs a deep comparison between each element in `collection` and the
|
|
source object, returning the first element that has equivalent property
|
|
values.
|
|
<br>
|
|
<br>
|
|
**Note:** This method supports comparing arrays, booleans, `Date` objects,
|
|
numbers, `Object` objects, regexes, and strings. Objects are compared by
|
|
their own, not inherited, enumerable properties. For comparing a single
|
|
own or inherited property value see `_.matchesProperty`.
|
|
|
|
#### 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, 'active': true },
|
|
{ 'user': 'fred', 'age': 40, 'active': false }
|
|
];
|
|
|
|
_.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user');
|
|
// => 'barney'
|
|
|
|
_.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user');
|
|
// => 'fred'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_foreachcollection-iteratee_identity-thisarg"></a>`_.forEach(collection, [iteratee=_.identity], [thisArg])`
|
|
<a href="#_foreachcollection-iteratee_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6605 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.foreach "See the npm package")
|
|
|
|
Iterates over elements of `collection` invoking `iteratee` for each element.
|
|
The `iteratee` is bound to `thisArg` and invoked with three arguments:<br>
|
|
(value, index|key, collection). Iteratee functions may exit iteration early
|
|
by explicitly returning `false`.
|
|
<br>
|
|
<br>
|
|
**Note:** As with other "Collections" methods, objects with a "length" property
|
|
are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
|
|
may be used for object iteration.
|
|
|
|
#### Aliases
|
|
*_.each*
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to iterate over.
|
|
2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Array|Object|string)*: Returns `collection`.
|
|
|
|
#### Example
|
|
```js
|
|
_([1, 2]).forEach(function(n) {
|
|
console.log(n);
|
|
}).value();
|
|
// => logs each value from left to right and returns the array
|
|
|
|
_.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
|
|
console.log(n, key);
|
|
});
|
|
// => logs each value-key pair and returns the object (iteration order is not guaranteed)
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_foreachrightcollection-iteratee_identity-thisarg"></a>`_.forEachRight(collection, [iteratee=_.identity], [thisArg])`
|
|
<a href="#_foreachrightcollection-iteratee_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6626 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.foreachright "See the npm package")
|
|
|
|
This method is like `_.forEach` except that it iterates over elements of
|
|
`collection` from right to left.
|
|
|
|
#### Aliases
|
|
*_.eachRight*
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to iterate over.
|
|
2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Array|Object|string)*: Returns `collection`.
|
|
|
|
#### Example
|
|
```js
|
|
_([1, 2]).forEachRight(function(n) {
|
|
console.log(n);
|
|
}).value();
|
|
// => logs each value from right to left and returns the array
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_groupbycollection-iteratee_identity-thisarg"></a>`_.groupBy(collection, [iteratee=_.identity], [thisArg])`
|
|
<a href="#_groupbycollection-iteratee_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6670 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.groupby "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 an array of the elements responsible for generating the key.
|
|
The `iteratee` is bound to `thisArg` and invoked with three arguments:<br>
|
|
(value, index|key, collection).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `iteratee` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
If an object is provided for `iteratee` 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=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the composed aggregate object.
|
|
|
|
#### Example
|
|
```js
|
|
_.groupBy([4.2, 6.1, 6.4], function(n) {
|
|
return Math.floor(n);
|
|
});
|
|
// => { '4': [4.2], '6': [6.1, 6.4] }
|
|
|
|
_.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
|
|
_.groupBy(['one', 'two', 'three'], 'length');
|
|
// => { '3': ['one', 'two'], '5': ['three'] }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_includescollection-target-fromindex0"></a>`_.includes(collection, target, [fromIndex=0])`
|
|
<a href="#_includescollection-target-fromindex0">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6707 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.includes "See the npm package")
|
|
|
|
Checks if `target` is in `collection` using
|
|
[`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
|
|
for equality comparisons. If `fromIndex` is negative, it's used as the offset
|
|
from the end of `collection`.
|
|
|
|
#### Aliases
|
|
*_.contains, _.include*
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to search.
|
|
2. `target` *(*)*: The value to search for.
|
|
3. `[fromIndex=0]` *(number)*: The index to search from.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if a matching element is found, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.includes([1, 2, 3], 1);
|
|
// => true
|
|
|
|
_.includes([1, 2, 3], 1, 2);
|
|
// => false
|
|
|
|
_.includes({ 'user': 'fred', 'age': 40 }, 'fred');
|
|
// => true
|
|
|
|
_.includes('pebbles', 'eb');
|
|
// => true
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_indexbycollection-iteratee_identity-thisarg"></a>`_.indexBy(collection, [iteratee=_.identity], [thisArg])`
|
|
<a href="#_indexbycollection-iteratee_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6769 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.indexby "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:<br>
|
|
(value, index|key, collection).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `iteratee` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
If an object is provided for `iteratee` 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=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the composed aggregate object.
|
|
|
|
#### Example
|
|
```js
|
|
var keyData = [
|
|
{ 'dir': 'left', 'code': 97 },
|
|
{ '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);
|
|
}, String);
|
|
// => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_invokecollection-path-args"></a>`_.invoke(collection, path, [args])`
|
|
<a href="#_invokecollection-path-args">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6795 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.invoke "See the npm package")
|
|
|
|
Invokes the method at `path` of each element in `collection`, returning
|
|
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
|
|
invoked for, and `this` bound to, each element in `collection`.
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to iterate over.
|
|
2. `path` *(Array|Function|string)*: The path of the method to invoke or the function invoked per iteration.
|
|
3. `[args]` *(...*)*: The arguments to invoke the method with.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the array of results.
|
|
|
|
#### Example
|
|
```js
|
|
_.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
|
|
// => [[1, 5, 7], [1, 2, 3]]
|
|
|
|
_.invoke([123, 456], String.prototype.split, '');
|
|
// => [['1', '2', '3'], ['4', '5', '6']]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_mapcollection-iteratee_identity-thisarg"></a>`_.map(collection, [iteratee=_.identity], [thisArg])`
|
|
<a href="#_mapcollection-iteratee_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6864 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.map "See the npm package")
|
|
|
|
Creates an array of values by running each element in `collection` through
|
|
`iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
|
|
arguments: (value, index|key, collection).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `iteratee` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
If an object is provided for `iteratee` the created `_.matches` style
|
|
callback returns `true` for elements that have the properties of the given
|
|
object, else `false`.
|
|
<br>
|
|
<br>
|
|
Many lodash methods are guarded to work as iteratees for methods like
|
|
`_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
|
|
<br>
|
|
<br>
|
|
The guarded methods are:<br>
|
|
`ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
|
|
`drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
|
|
`parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
|
|
`trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
|
|
`sum`, `uniq`, and `words`
|
|
|
|
#### Aliases
|
|
*_.collect*
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to iterate over.
|
|
2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new mapped array.
|
|
|
|
#### Example
|
|
```js
|
|
function timesThree(n) {
|
|
return n * 3;
|
|
}
|
|
|
|
_.map([1, 2], timesThree);
|
|
// => [3, 6]
|
|
|
|
_.map({ 'a': 1, 'b': 2 }, timesThree);
|
|
// => [3, 6] (iteration order is not guaranteed)
|
|
|
|
var users = [
|
|
{ 'user': 'barney' },
|
|
{ 'user': 'fred' }
|
|
];
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.map(users, 'user');
|
|
// => ['barney', 'fred']
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_partitioncollection-predicate_identity-thisarg"></a>`_.partition(collection, [predicate=_.identity], [thisArg])`
|
|
<a href="#_partitioncollection-predicate_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6929 "View in source") [Ⓣ][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
|
|
contains elements `predicate` returns truthy for, while the second of which
|
|
contains elements `predicate` returns falsey for. The predicate is bound
|
|
to `thisArg` and invoked with three arguments: (value, index|key, collection).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `predicate` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
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. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the array of grouped elements.
|
|
|
|
#### Example
|
|
```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.2, 3.4], [2.3]]
|
|
|
|
var users = [
|
|
{ 'user': 'barney', 'age': 36, 'active': false },
|
|
{ 'user': 'fred', 'age': 40, 'active': true },
|
|
{ 'user': 'pebbles', 'age': 1, 'active': false }
|
|
];
|
|
|
|
var mapper = function(array) {
|
|
return _.pluck(array, 'user');
|
|
};
|
|
|
|
// using the `_.matches` callback shorthand
|
|
_.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
|
|
// => [['pebbles'], ['barney', 'fred']]
|
|
|
|
// using the `_.matchesProperty` callback shorthand
|
|
_.map(_.partition(users, 'active', false), mapper);
|
|
// => [['barney', 'pebbles'], ['fred']]
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.map(_.partition(users, 'active'), mapper);
|
|
// => [['fred'], ['barney', 'pebbles']]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_pluckcollection-path"></a>`_.pluck(collection, path)`
|
|
<a href="#_pluckcollection-path">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6956 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.pluck "See the npm package")
|
|
|
|
Gets the property value of `path` from all elements in `collection`.
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to iterate over.
|
|
2. `path` *(Array|string)*: The path 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');
|
|
// => ['barney', 'fred']
|
|
|
|
var userIndex = _.indexBy(users, 'user');
|
|
_.pluck(userIndex, 'age');
|
|
// => [36, 40] (iteration order is not guaranteed)
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_reducecollection-iteratee_identity-accumulator-thisarg"></a>`_.reduce(collection, [iteratee=_.identity], [accumulator], [thisArg])`
|
|
<a href="#_reducecollection-iteratee_identity-accumulator-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L6997 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.reduce "See the npm package")
|
|
|
|
Reduces `collection` to a value which is the accumulated result of running
|
|
each element in `collection` through `iteratee`, where each successive
|
|
invocation is supplied the return value of the previous. If `accumulator`
|
|
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:<br>
|
|
(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`, `sortByAll`,
|
|
and `sortByOrder`
|
|
|
|
#### Aliases
|
|
*_.foldl, _.inject*
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to iterate over.
|
|
2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration.
|
|
3. `[accumulator]` *(*)*: The initial value.
|
|
4. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(*)*: Returns the accumulated value.
|
|
|
|
#### Example
|
|
```js
|
|
_.reduce([1, 2], function(total, n) {
|
|
return total + n;
|
|
});
|
|
// => 3
|
|
|
|
_.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
|
|
result[key] = n * 3;
|
|
return result;
|
|
}, {});
|
|
// => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_reducerightcollection-iteratee_identity-accumulator-thisarg"></a>`_.reduceRight(collection, [iteratee=_.identity], [accumulator], [thisArg])`
|
|
<a href="#_reducerightcollection-iteratee_identity-accumulator-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7021 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.reduceright "See the npm package")
|
|
|
|
This method is like `_.reduce` except that it iterates over elements of
|
|
`collection` from right to left.
|
|
|
|
#### Aliases
|
|
*_.foldr*
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to iterate over.
|
|
2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration.
|
|
3. `[accumulator]` *(*)*: The initial value.
|
|
4. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(*)*: Returns the accumulated value.
|
|
|
|
#### Example
|
|
```js
|
|
var array = [[0, 1], [2, 3], [4, 5]];
|
|
|
|
_.reduceRight(array, function(flattened, other) {
|
|
return flattened.concat(other);
|
|
}, []);
|
|
// => [4, 5, 2, 3, 0, 1]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_rejectcollection-predicate_identity-thisarg"></a>`_.reject(collection, [predicate=_.identity], [thisArg])`
|
|
<a href="#_rejectcollection-predicate_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7059 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.reject "See the npm package")
|
|
|
|
The opposite of `_.filter`; this method returns the elements of `collection`
|
|
that `predicate` does **not** return truthy for.
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to iterate over.
|
|
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new filtered array.
|
|
|
|
#### Example
|
|
```js
|
|
_.reject([1, 2, 3, 4], function(n) {
|
|
return n % 2 == 0;
|
|
});
|
|
// => [1, 3]
|
|
|
|
var users = [
|
|
{ 'user': 'barney', 'age': 36, 'active': false },
|
|
{ 'user': 'fred', 'age': 40, 'active': true }
|
|
];
|
|
|
|
// using the `_.matches` callback shorthand
|
|
_.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
|
|
// => ['barney']
|
|
|
|
// using the `_.matchesProperty` callback shorthand
|
|
_.pluck(_.reject(users, 'active', false), 'user');
|
|
// => ['fred']
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.pluck(_.reject(users, 'active'), 'user');
|
|
// => ['barney']
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_samplecollection-n"></a>`_.sample(collection, [n])`
|
|
<a href="#_samplecollection-n">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7085 "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.
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to sample.
|
|
2. `[n]` *(number)*: The number of elements to sample.
|
|
|
|
#### Returns
|
|
*(*)*: Returns the random sample(s).
|
|
|
|
#### Example
|
|
```js
|
|
_.sample([1, 2, 3, 4]);
|
|
// => 2
|
|
|
|
_.sample([1, 2, 3, 4], 2);
|
|
// => [3, 1]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_shufflecollection"></a>`_.shuffle(collection)`
|
|
<a href="#_shufflecollection">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7122 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.shuffle "See the npm package")
|
|
|
|
Creates an array of shuffled values, using a version of the
|
|
[Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to shuffle.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new shuffled array.
|
|
|
|
#### Example
|
|
```js
|
|
_.shuffle([1, 2, 3, 4]);
|
|
// => [4, 1, 3, 2]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_sizecollection"></a>`_.size(collection)`
|
|
<a href="#_sizecollection">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7146 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.size "See the npm package")
|
|
|
|
Gets the size of `collection` by returning its length for array-like
|
|
values or the number of own enumerable properties for objects.
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to inspect.
|
|
|
|
#### Returns
|
|
*(number)*: Returns the size of `collection`.
|
|
|
|
#### Example
|
|
```js
|
|
_.size([1, 2, 3]);
|
|
// => 3
|
|
|
|
_.size({ 'a': 1, 'b': 2 });
|
|
// => 2
|
|
|
|
_.size('pebbles');
|
|
// => 7
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_somecollection-predicate_identity-thisarg"></a>`_.some(collection, [predicate=_.identity], [thisArg])`
|
|
<a href="#_somecollection-predicate_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7200 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.some "See the npm package")
|
|
|
|
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).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `predicate` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
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`.
|
|
|
|
#### Aliases
|
|
*_.any*
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to iterate over.
|
|
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if any element passes the predicate check,
|
|
else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.some([null, 0, 'yes', false], Boolean);
|
|
// => true
|
|
|
|
var users = [
|
|
{ 'user': 'barney', 'active': true },
|
|
{ 'user': 'fred', 'active': false }
|
|
];
|
|
|
|
// using the `_.matches` callback shorthand
|
|
_.some(users, { 'user': 'barney', 'active': false });
|
|
// => false
|
|
|
|
// using the `_.matchesProperty` callback shorthand
|
|
_.some(users, 'active', false);
|
|
// => true
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.some(users, 'active');
|
|
// => true
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_sortbycollection-iteratee_identity-thisarg"></a>`_.sortBy(collection, [iteratee=_.identity], [thisArg])`
|
|
<a href="#_sortbycollection-iteratee_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7259 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.sortby "See the npm package")
|
|
|
|
Creates an array of elements, sorted in ascending order by the results of
|
|
running each element in a collection through `iteratee`. This method performs
|
|
a stable sort, that is, it preserves the original sort order of equal elements.
|
|
The `iteratee` is bound to `thisArg` and invoked with three arguments:<br>
|
|
(value, index|key, collection).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `iteratee` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
If an object is provided for `iteratee` 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=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new sorted array.
|
|
|
|
#### Example
|
|
```js
|
|
_.sortBy([1, 2, 3], function(n) {
|
|
return Math.sin(n);
|
|
});
|
|
// => [3, 1, 2]
|
|
|
|
_.sortBy([1, 2, 3], function(n) {
|
|
return this.sin(n);
|
|
}, Math);
|
|
// => [3, 1, 2]
|
|
|
|
var users = [
|
|
{ 'user': 'fred' },
|
|
{ 'user': 'pebbles' },
|
|
{ 'user': 'barney' }
|
|
];
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.pluck(_.sortBy(users, 'user'), 'user');
|
|
// => ['barney', 'fred', 'pebbles']
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_sortbyallcollection-iteratees"></a>`_.sortByAll(collection, iteratees)`
|
|
<a href="#_sortbyallcollection-iteratees">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7310 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.sortbyall "See the npm package")
|
|
|
|
This method is like `_.sortBy` except that it can sort by multiple iteratees
|
|
or property names.
|
|
<br>
|
|
<br>
|
|
If a property name is provided for an iteratee the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If an object is provided for an iteratee 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. `iteratees` *(...(Function|Function[]|Object|Object[]|string|string[])*: The iteratees to sort by, specified as individual values or arrays of values.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new sorted array.
|
|
|
|
#### Example
|
|
```js
|
|
var users = [
|
|
{ 'user': 'fred', 'age': 48 },
|
|
{ 'user': 'barney', 'age': 36 },
|
|
{ 'user': 'fred', 'age': 42 },
|
|
{ 'user': 'barney', 'age': 34 }
|
|
];
|
|
|
|
_.map(_.sortByAll(users, ['user', 'age']), _.values);
|
|
// => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
|
|
|
|
_.map(_.sortByAll(users, 'user', function(chr) {
|
|
return Math.floor(chr.age / 10);
|
|
}), _.values);
|
|
// => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_sortbyordercollection-iteratees-orders"></a>`_.sortByOrder(collection, iteratees, [orders])`
|
|
<a href="#_sortbyordercollection-iteratees-orders">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7355 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.sortbyorder "See the npm package")
|
|
|
|
This method is like `_.sortByAll` except that it allows specifying the
|
|
sort orders of the iteratees to sort by. If `orders` is unspecified, all
|
|
values are sorted in ascending order. Otherwise, a value is sorted in
|
|
ascending order if its corresponding order is "asc", and descending if "desc".
|
|
<br>
|
|
<br>
|
|
If a property name is provided for an iteratee the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If an object is provided for an iteratee 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. `iteratees` *(Function[]|Object[]|string[])*: The iteratees to sort by.
|
|
3. `[orders]` *(boolean[])*: The sort orders of `iteratees`.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new sorted array.
|
|
|
|
#### Example
|
|
```js
|
|
var users = [
|
|
{ 'user': 'fred', 'age': 48 },
|
|
{ 'user': 'barney', 'age': 34 },
|
|
{ 'user': 'fred', 'age': 42 },
|
|
{ 'user': 'barney', 'age': 36 }
|
|
];
|
|
|
|
// sort by `user` in ascending order and by `age` in descending order
|
|
_.map(_.sortByOrder(users, ['user', 'age'], ['asc', 'desc']), _.values);
|
|
// => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_wherecollection-source"></a>`_.where(collection, source)`
|
|
<a href="#_wherecollection-source">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7400 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.where "See the npm package")
|
|
|
|
Performs a deep comparison between each element in `collection` and the
|
|
source object, returning an array of all elements that have equivalent
|
|
property values.
|
|
<br>
|
|
<br>
|
|
**Note:** This method supports comparing arrays, booleans, `Date` objects,
|
|
numbers, `Object` objects, regexes, and strings. Objects are compared by
|
|
their own, not inherited, enumerable properties. For comparing a single
|
|
own or inherited property value see `_.matchesProperty`.
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to search.
|
|
2. `source` *(Object)*: The object of property values to match.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new filtered array.
|
|
|
|
#### Example
|
|
```js
|
|
var users = [
|
|
{ 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] },
|
|
{ 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] }
|
|
];
|
|
|
|
_.pluck(_.where(users, { 'age': 36, 'active': false }), 'user');
|
|
// => ['barney']
|
|
|
|
_.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
|
|
// => ['fred']
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `“Date” Methods`
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_now"></a>`_.now`
|
|
<a href="#_now">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7420 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.now "See the npm package")
|
|
|
|
Gets the number of milliseconds that have elapsed since the Unix epoch
|
|
(1 January 1970 00:00:00 UTC).
|
|
|
|
#### Example
|
|
```js
|
|
_.defer(function(stamp) {
|
|
console.log(_.now() - stamp);
|
|
}, _.now());
|
|
// => logs the number of milliseconds it took for the deferred function to be invoked
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `“Function” Methods`
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_aftern-func"></a>`_.after(n, func)`
|
|
<a href="#_aftern-func">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7449 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.after "See the npm package")
|
|
|
|
The opposite of `_.before`; this method creates a function that invokes
|
|
`func` once it's called `n` or more times.
|
|
|
|
#### Arguments
|
|
1. `n` *(number)*: The number of calls before `func` is invoked.
|
|
2. `func` *(Function)*: The function to restrict.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new restricted function.
|
|
|
|
#### Example
|
|
```js
|
|
var saves = ['profile', 'settings'];
|
|
|
|
var done = _.after(saves.length, function() {
|
|
console.log('done saving!');
|
|
});
|
|
|
|
_.forEach(saves, function(type) {
|
|
asyncSave({ 'type': type, 'complete': done });
|
|
});
|
|
// => logs 'done saving!' after the two async saves have completed
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_aryfunc-nfunclength"></a>`_.ary(func, [n=func.length])`
|
|
<a href="#_aryfunc-nfunclength">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7483 "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
|
|
additional arguments.
|
|
|
|
#### Arguments
|
|
1. `func` *(Function)*: The function to cap arguments for.
|
|
2. `[n=func.length]` *(number)*: The arity cap.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new function.
|
|
|
|
#### Example
|
|
```js
|
|
_.map(['6', '8', '10'], _.ary(parseInt, 1));
|
|
// => [6, 8, 10]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_beforen-func"></a>`_.before(n, func)`
|
|
<a href="#_beforen-func">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7507 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.before "See the npm package")
|
|
|
|
Creates a function that invokes `func`, with the `this` binding and arguments
|
|
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.
|
|
|
|
#### Arguments
|
|
1. `n` *(number)*: The number of calls at which `func` is no longer invoked.
|
|
2. `func` *(Function)*: The function to restrict.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new restricted function.
|
|
|
|
#### Example
|
|
```js
|
|
jQuery('#add').on('click', _.before(5, addContactToList));
|
|
// => allows adding up to 4 contacts to the list
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_bindfunc-thisarg-partials"></a>`_.bind(func, thisArg, [partials])`
|
|
<a href="#_bindfunc-thisarg-partials">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7564 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.bind "See the npm package")
|
|
|
|
Creates a function that invokes `func` with the `this` binding of `thisArg`
|
|
and prepends any additional `_.bind` arguments to those provided to the
|
|
bound function.
|
|
<br>
|
|
<br>
|
|
The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
|
|
may be used as a placeholder for partially applied arguments.
|
|
<br>
|
|
<br>
|
|
**Note:** Unlike native `Function#bind` this method does not set the "length"
|
|
property of bound functions.
|
|
|
|
#### Arguments
|
|
1. `func` *(Function)*: The function to bind.
|
|
2. `thisArg` *(*)*: The `this` binding of `func`.
|
|
3. `[partials]` *(...*)*: The arguments to be partially applied.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new bound function.
|
|
|
|
#### Example
|
|
```js
|
|
var greet = function(greeting, punctuation) {
|
|
return greeting + ' ' + this.user + punctuation;
|
|
};
|
|
|
|
var object = { 'user': 'fred' };
|
|
|
|
var bound = _.bind(greet, object, 'hi');
|
|
bound('!');
|
|
// => 'hi fred!'
|
|
|
|
// using placeholders
|
|
var bound = _.bind(greet, object, _, '!');
|
|
bound('hi');
|
|
// => 'hi fred!'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_bindallobject-methodnames"></a>`_.bindAll(object, [methodNames])`
|
|
<a href="#_bindallobject-methodnames">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7601 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.bindall "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.
|
|
<br>
|
|
<br>
|
|
**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 bind, 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-partials"></a>`_.bindKey(object, key, [partials])`
|
|
<a href="#_bindkeyobject-key-partials">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7658 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.bindkey "See the npm package")
|
|
|
|
Creates a function that invokes the method at `object[key]` and prepends
|
|
any additional `_.bindKey` arguments to those provided to the bound function.
|
|
<br>
|
|
<br>
|
|
This method differs from `_.bind` by allowing bound functions to reference
|
|
methods that may be redefined or don't yet exist.
|
|
See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
|
|
for more details.
|
|
<br>
|
|
<br>
|
|
The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
|
|
builds, may be used as a placeholder for partially applied arguments.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object the method belongs to.
|
|
2. `key` *(string)*: The key of the method.
|
|
3. `[partials]` *(...*)*: The arguments to be partially applied.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new bound function.
|
|
|
|
#### Example
|
|
```js
|
|
var object = {
|
|
'user': 'fred',
|
|
'greet': function(greeting, punctuation) {
|
|
return greeting + ' ' + this.user + punctuation;
|
|
}
|
|
};
|
|
|
|
var bound = _.bindKey(object, 'greet', 'hi');
|
|
bound('!');
|
|
// => 'hi fred!'
|
|
|
|
object.greet = function(greeting, punctuation) {
|
|
return greeting + 'ya ' + this.user + punctuation;
|
|
};
|
|
|
|
bound('!');
|
|
// => 'hiya fred!'
|
|
|
|
// using placeholders
|
|
var bound = _.bindKey(object, 'greet', _, '!');
|
|
bound('hi');
|
|
// => 'hiya fred!'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_curryfunc-arityfunclength"></a>`_.curry(func, [arity=func.length])`
|
|
<a href="#_curryfunc-arityfunclength">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7707 "View in source") [Ⓣ][1] [Ⓝ](https://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.
|
|
<br>
|
|
<br>
|
|
The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
|
|
may be used as a placeholder for provided arguments.
|
|
<br>
|
|
<br>
|
|
**Note:** This method does not set the "length" property of curried functions.
|
|
|
|
#### Arguments
|
|
1. `func` *(Function)*: The function to curry.
|
|
2. `[arity=func.length]` *(number)*: The arity of `func`.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new curried function.
|
|
|
|
#### Example
|
|
```js
|
|
var abc = function(a, b, c) {
|
|
return [a, b, c];
|
|
};
|
|
|
|
var curried = _.curry(abc);
|
|
|
|
curried(1)(2)(3);
|
|
// => [1, 2, 3]
|
|
|
|
curried(1, 2)(3);
|
|
// => [1, 2, 3]
|
|
|
|
curried(1, 2, 3);
|
|
// => [1, 2, 3]
|
|
|
|
// using placeholders
|
|
curried(1)(_, 3)(2);
|
|
// => [1, 2, 3]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_curryrightfunc-arityfunclength"></a>`_.curryRight(func, [arity=func.length])`
|
|
<a href="#_curryrightfunc-arityfunclength">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7746 "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`
|
|
in the manner of `_.partialRight` instead of `_.partial`.
|
|
<br>
|
|
<br>
|
|
The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
|
|
builds, may be used as a placeholder for provided arguments.
|
|
<br>
|
|
<br>
|
|
**Note:** This method does not set the "length" property of curried functions.
|
|
|
|
#### Arguments
|
|
1. `func` *(Function)*: The function to curry.
|
|
2. `[arity=func.length]` *(number)*: The arity of `func`.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new curried function.
|
|
|
|
#### Example
|
|
```js
|
|
var abc = function(a, b, c) {
|
|
return [a, b, c];
|
|
};
|
|
|
|
var curried = _.curryRight(abc);
|
|
|
|
curried(3)(2)(1);
|
|
// => [1, 2, 3]
|
|
|
|
curried(2, 3)(1);
|
|
// => [1, 2, 3]
|
|
|
|
curried(1, 2, 3);
|
|
// => [1, 2, 3]
|
|
|
|
// using placeholders
|
|
curried(3)(1, _)(2);
|
|
// => [1, 2, 3]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_debouncefunc-wait0-options"></a>`_.debounce(func, [wait=0], [options])`
|
|
<a href="#_debouncefunc-wait0-options">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7811 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.debounce "See the npm package")
|
|
|
|
Creates a debounced function that delays invoking `func` until after `wait`
|
|
milliseconds have elapsed since the last time the debounced function was
|
|
invoked. The debounced function comes with a `cancel` method to cancel
|
|
delayed invocations. Provide an options object to indicate that `func`
|
|
should be invoked on the leading and/or trailing edge of the `wait` timeout.
|
|
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
|
|
invoked more than once during the `wait` timeout.
|
|
<br>
|
|
<br>
|
|
See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
|
|
for details over the differences between `_.debounce` and `_.throttle`.
|
|
|
|
#### Arguments
|
|
1. `func` *(Function)*: The function to debounce.
|
|
2. `[wait=0]` *(number)*: The number of milliseconds to delay.
|
|
3. `[options]` *(Object)*: The options object.
|
|
4. `[options.leading=false]` *(boolean)*: Specify invoking on the leading edge of the timeout.
|
|
5. `[options.maxWait]` *(number)*: The maximum time `func` is allowed to be delayed before it's invoked.
|
|
6. `[options.trailing=true]` *(boolean)*: Specify invoking on the trailing edge of the timeout.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new debounced function.
|
|
|
|
#### Example
|
|
```js
|
|
// avoid costly calculations while the window size is in flux
|
|
jQuery(window).on('resize', _.debounce(calculateLayout, 150));
|
|
|
|
// invoke `sendMail` when the click event is fired, debouncing subsequent calls
|
|
jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
|
|
'leading': true,
|
|
'trailing': false
|
|
}));
|
|
|
|
// ensure `batchLog` is invoked once after 1 second of debounced calls
|
|
var source = new EventSource('/stream');
|
|
jQuery(source).on('message', _.debounce(batchLog, 250, {
|
|
'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
|
|
// which cancels the debounced `todoChanges` call
|
|
delete models.todo;
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_deferfunc-args"></a>`_.defer(func, [args])`
|
|
<a href="#_deferfunc-args">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7936 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.defer "See the npm package")
|
|
|
|
Defers invoking the `func` until the current call stack has cleared. Any
|
|
additional arguments are provided to `func` when it's invoked.
|
|
|
|
#### Arguments
|
|
1. `func` *(Function)*: The function to defer.
|
|
2. `[args]` *(...*)*: The arguments to invoke the function with.
|
|
|
|
#### Returns
|
|
*(number)*: Returns the timer id.
|
|
|
|
#### Example
|
|
```js
|
|
_.defer(function(text) {
|
|
console.log(text);
|
|
}, 'deferred');
|
|
// logs 'deferred' after one or more milliseconds
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_delayfunc-wait-args"></a>`_.delay(func, wait, [args])`
|
|
<a href="#_delayfunc-wait-args">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7958 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.delay "See the npm package")
|
|
|
|
Invokes `func` after `wait` milliseconds. Any additional arguments are
|
|
provided to `func` when it's invoked.
|
|
|
|
#### Arguments
|
|
1. `func` *(Function)*: The function to delay.
|
|
2. `wait` *(number)*: The number of milliseconds to delay invocation.
|
|
3. `[args]` *(...*)*: The arguments to invoke the function with.
|
|
|
|
#### Returns
|
|
*(number)*: Returns the timer id.
|
|
|
|
#### Example
|
|
```js
|
|
_.delay(function(text) {
|
|
console.log(text);
|
|
}, 1000, 'later');
|
|
// => logs 'later' after one second
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_flowfuncs"></a>`_.flow([funcs])`
|
|
<a href="#_flowfuncs">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L7982 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.flow "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 square(n) {
|
|
return n * n;
|
|
}
|
|
|
|
var addSquare = _.flow(_.add, square);
|
|
addSquare(1, 2);
|
|
// => 9
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_flowrightfuncs"></a>`_.flowRight([funcs])`
|
|
<a href="#_flowrightfuncs">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8004 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.flowright "See the npm package")
|
|
|
|
This method is like `_.flow` except that it creates a function that
|
|
invokes the provided functions from right to left.
|
|
|
|
#### Aliases
|
|
*_.backflow, _.compose*
|
|
|
|
#### Arguments
|
|
1. `[funcs]` *(...Function)*: Functions to invoke.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new function.
|
|
|
|
#### Example
|
|
```js
|
|
function square(n) {
|
|
return n * n;
|
|
}
|
|
|
|
var addSquare = _.flowRight(square, _.add);
|
|
addSquare(1, 2);
|
|
// => 9
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_memoizefunc-resolver"></a>`_.memoize(func, [resolver])`
|
|
<a href="#_memoizefunc-resolver">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8057 "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
|
|
provided it determines the cache key for storing the result based on the
|
|
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
|
|
cache key. The `func` is invoked with the `this` binding of the memoized
|
|
function.
|
|
<br>
|
|
<br>
|
|
**Note:** The cache is exposed as the `cache` property on the memoized
|
|
function. Its creation may be customized by replacing the `_.memoize.Cache`
|
|
constructor with one whose instances implement the [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
|
|
method interface of `get`, `has`, and `set`.
|
|
|
|
#### Arguments
|
|
1. `func` *(Function)*: The function to have its output memoized.
|
|
2. `[resolver]` *(Function)*: The function to resolve the cache key.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new memoizing function.
|
|
|
|
#### Example
|
|
```js
|
|
var upperCase = _.memoize(function(string) {
|
|
return string.toUpperCase();
|
|
});
|
|
|
|
upperCase('fred');
|
|
// => 'FRED'
|
|
|
|
// modifying the result cache
|
|
upperCase.cache.set('fred', 'BARNEY');
|
|
upperCase('fred');
|
|
// => 'BARNEY'
|
|
|
|
// replacing `_.memoize.Cache`
|
|
var object = { 'user': 'fred' };
|
|
var other = { 'user': 'barney' };
|
|
var identity = _.memoize(_.identity);
|
|
|
|
identity(object);
|
|
// => { 'user': 'fred' }
|
|
identity(other);
|
|
// => { 'user': 'fred' }
|
|
|
|
_.memoize.Cache = WeakMap;
|
|
var identity = _.memoize(_.identity);
|
|
|
|
identity(object);
|
|
// => { 'user': 'fred' }
|
|
identity(other);
|
|
// => { 'user': 'barney' }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_modargsfunc-transforms"></a>`_.modArgs(func, [transforms])`
|
|
<a href="#_modargsfunc-transforms">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8108 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.modargs "See the npm package")
|
|
|
|
Creates a function that runs each argument through a corresponding
|
|
transform function.
|
|
|
|
#### Arguments
|
|
1. `func` *(Function)*: The function to wrap.
|
|
2. `[transforms]` *(...(Function|Function[])*: The functions to transform arguments, specified as individual functions or arrays of functions.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new function.
|
|
|
|
#### Example
|
|
```js
|
|
function doubled(n) {
|
|
return n * 2;
|
|
}
|
|
|
|
function square(n) {
|
|
return n * n;
|
|
}
|
|
|
|
var modded = _.modArgs(function(x, y) {
|
|
return [x, y];
|
|
}, square, doubled);
|
|
|
|
modded(1, 2);
|
|
// => [1, 4]
|
|
|
|
modded(5, 10);
|
|
// => [25, 20]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_negatepredicate"></a>`_.negate(predicate)`
|
|
<a href="#_negatepredicate">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8142 "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
|
|
`func` predicate is invoked with the `this` binding and arguments of the
|
|
created function.
|
|
|
|
#### Arguments
|
|
1. `predicate` *(Function)*: The predicate to negate.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new function.
|
|
|
|
#### Example
|
|
```js
|
|
function isEven(n) {
|
|
return n % 2 == 0;
|
|
}
|
|
|
|
_.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
|
|
// => [1, 3, 5]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_oncefunc"></a>`_.once(func)`
|
|
<a href="#_oncefunc">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8168 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.once "See the npm package")
|
|
|
|
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
|
|
with the `this` binding and arguments of the created function.
|
|
|
|
#### Arguments
|
|
1. `func` *(Function)*: The function to restrict.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new restricted function.
|
|
|
|
#### Example
|
|
```js
|
|
var initialize = _.once(createApplication);
|
|
initialize();
|
|
initialize();
|
|
// `initialize` invokes `createApplication` once
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_partialfunc-partials"></a>`_.partial(func, [partials])`
|
|
<a href="#_partialfunc-partials">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8204 "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
|
|
to those provided to the new function. This method is like `_.bind` except
|
|
it does **not** alter the `this` binding.
|
|
<br>
|
|
<br>
|
|
The `_.partial.placeholder` value, which defaults to `_` in monolithic
|
|
builds, may be used as a placeholder for partially applied arguments.
|
|
<br>
|
|
<br>
|
|
**Note:** This method does not set the "length" property of partially
|
|
applied functions.
|
|
|
|
#### Arguments
|
|
1. `func` *(Function)*: The function to partially apply arguments to.
|
|
2. `[partials]` *(...*)*: The arguments to be partially applied.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new partially applied function.
|
|
|
|
#### Example
|
|
```js
|
|
var greet = function(greeting, name) {
|
|
return greeting + ' ' + name;
|
|
};
|
|
|
|
var sayHelloTo = _.partial(greet, 'hello');
|
|
sayHelloTo('fred');
|
|
// => 'hello fred'
|
|
|
|
// using placeholders
|
|
var greetFred = _.partial(greet, _, 'fred');
|
|
greetFred('hi');
|
|
// => 'hi fred'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_partialrightfunc-partials"></a>`_.partialRight(func, [partials])`
|
|
<a href="#_partialrightfunc-partials">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8237 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.partialright "See the npm package")
|
|
|
|
This method is like `_.partial` except that partially applied arguments
|
|
are appended to those provided to the new function.
|
|
<br>
|
|
<br>
|
|
The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
|
|
builds, may be used as a placeholder for partially applied arguments.
|
|
<br>
|
|
<br>
|
|
**Note:** This method does not set the "length" property of partially
|
|
applied functions.
|
|
|
|
#### Arguments
|
|
1. `func` *(Function)*: The function to partially apply arguments to.
|
|
2. `[partials]` *(...*)*: The arguments to be partially applied.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new partially applied function.
|
|
|
|
#### Example
|
|
```js
|
|
var greet = function(greeting, name) {
|
|
return greeting + ' ' + name;
|
|
};
|
|
|
|
var greetFred = _.partialRight(greet, 'fred');
|
|
greetFred('hi');
|
|
// => 'hi fred'
|
|
|
|
// using placeholders
|
|
var sayHelloTo = _.partialRight(greet, 'hello', _);
|
|
sayHelloTo('fred');
|
|
// => 'hello fred'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_reargfunc-indexes"></a>`_.rearg(func, indexes)`
|
|
<a href="#_reargfunc-indexes">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8267 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.rearg "See the npm package")
|
|
|
|
Creates a function that invokes `func` with arguments arranged according
|
|
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 second argument, and so on.
|
|
|
|
#### Arguments
|
|
1. `func` *(Function)*: The function to rearrange arguments for.
|
|
2. `indexes` *(...(number|number[])*: The arranged argument indexes, specified as individual indexes or arrays of indexes.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new function.
|
|
|
|
#### Example
|
|
```js
|
|
var rearged = _.rearg(function(a, b, c) {
|
|
return [a, b, c];
|
|
}, 2, 0, 1);
|
|
|
|
rearged('b', 'c', 'a')
|
|
// => ['a', 'b', 'c']
|
|
|
|
var map = _.rearg(_.map, [1, 0]);
|
|
map(function(n) {
|
|
return n * 3;
|
|
}, [1, 2, 3]);
|
|
// => [3, 6, 9]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_restparamfunc-startfunclength-1"></a>`_.restParam(func, [start=func.length-1])`
|
|
<a href="#_restparamfunc-startfunclength-1">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8293 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.restparam "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://developer.mozilla.org/Web/JavaScript/Reference/Functions/rest_parameters).
|
|
|
|
#### 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 = _.restParam(function(what, names) {
|
|
return what + ' ' + _.initial(names).join(', ') +
|
|
(_.size(names) > 1 ? ', & ' : '') + _.last(names);
|
|
});
|
|
|
|
say('hello', 'fred', 'barney', 'pebbles');
|
|
// => 'hello fred, barney, & pebbles'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_spreadfunc"></a>`_.spread(func)`
|
|
<a href="#_spreadfunc">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8353 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.spread "See the npm package")
|
|
|
|
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.github.io/#x15.3.4.3).
|
|
<br>
|
|
<br>
|
|
**Note:** This method is based on the [spread operator](https://developer.mozilla.org/Web/JavaScript/Reference/Operators/Spread_operator).
|
|
|
|
#### 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)
|
|
]);
|
|
|
|
numbers.then(_.spread(function(x, y) {
|
|
return x + y;
|
|
}));
|
|
// => a Promise of 76
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_throttlefunc-wait0-options"></a>`_.throttle(func, [wait=0], [options])`
|
|
<a href="#_throttlefunc-wait0-options">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8401 "View in source") [Ⓣ][1] [Ⓝ](https://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 invocations. Provide an options object to indicate
|
|
that `func` should be invoked on the leading and/or trailing edge of the
|
|
`wait` timeout. Subsequent calls to the throttled function return the
|
|
result of the last `func` call.
|
|
<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
|
|
invoked more than once during the `wait` timeout.
|
|
<br>
|
|
<br>
|
|
See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
|
|
for details over the differences between `_.throttle` and `_.debounce`.
|
|
|
|
#### Arguments
|
|
1. `func` *(Function)*: The function to throttle.
|
|
2. `[wait=0]` *(number)*: The number of milliseconds to throttle invocations to.
|
|
3. `[options]` *(Object)*: The options object.
|
|
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.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new throttled function.
|
|
|
|
#### Example
|
|
```js
|
|
// avoid excessively updating the position while scrolling
|
|
jQuery(window).on('scroll', _.throttle(updatePosition, 100));
|
|
|
|
// invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
|
|
jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
|
|
'trailing': false
|
|
}));
|
|
|
|
// cancel a trailing throttled call
|
|
jQuery(window).on('popstate', throttled.cancel);
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_wrapvalue-wrapper"></a>`_.wrap(value, wrapper)`
|
|
<a href="#_wrapvalue-wrapper">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8438 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.wrap "See the npm package")
|
|
|
|
Creates a function that provides `value` to the wrapper function as its
|
|
first argument. Any additional arguments provided to the function are
|
|
appended to those provided to the wrapper function. The wrapper is invoked
|
|
with the `this` binding of the created function.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to wrap.
|
|
2. `wrapper` *(Function)*: The wrapper function.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new function.
|
|
|
|
#### Example
|
|
```js
|
|
var p = _.wrap(_.escape, function(func, text) {
|
|
return '<p>' + func(text) + '</p>';
|
|
});
|
|
|
|
p('fred, barney, & pebbles');
|
|
// => '<p>fred, barney, & pebbles</p>'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `“Lang” Methods`
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_clonevalue-isdeep-customizer-thisarg"></a>`_.clone(value, [isDeep], [customizer], [thisArg])`
|
|
<a href="#_clonevalue-isdeep-customizer-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8496 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.clone "See the npm package")
|
|
|
|
Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,
|
|
otherwise they are assigned by reference. If `customizer` is provided it's
|
|
invoked to produce the cloned values. If `customizer` returns `undefined`
|
|
cloning is handled by the method instead. The `customizer` is bound to
|
|
`thisArg` and invoked with up to three argument; (value [, index|key, object]).
|
|
<br>
|
|
<br>
|
|
**Note:** This method is loosely based on the
|
|
[structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-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.
|
|
|
|
#### Arguments
|
|
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 the cloned value.
|
|
|
|
#### Example
|
|
```js
|
|
var users = [
|
|
{ 'user': 'barney' },
|
|
{ 'user': 'fred' }
|
|
];
|
|
|
|
var shallow = _.clone(users);
|
|
shallow[0] === users[0];
|
|
// => true
|
|
|
|
var deep = _.clone(users, true);
|
|
deep[0] === users[0];
|
|
// => false
|
|
|
|
// using a customizer callback
|
|
var el = _.clone(document.body, function(value) {
|
|
if (_.isElement(value)) {
|
|
return value.cloneNode(false);
|
|
}
|
|
});
|
|
|
|
el === document.body
|
|
// => false
|
|
el.nodeName
|
|
// => BODY
|
|
el.childNodes.length;
|
|
// => 0
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_clonedeepvalue-customizer-thisarg"></a>`_.cloneDeep(value, [customizer], [thisArg])`
|
|
<a href="#_clonedeepvalue-customizer-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8555 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.clonedeep "See the npm package")
|
|
|
|
Creates a deep clone of `value`. If `customizer` is provided it's invoked
|
|
to produce the cloned values. If `customizer` returns `undefined` cloning
|
|
is handled by the method instead. The `customizer` is bound to `thisArg`
|
|
and invoked with up to three argument; (value [, index|key, object]).
|
|
<br>
|
|
<br>
|
|
**Note:** This method is loosely based on the
|
|
[structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-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.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to deep clone.
|
|
2. `[customizer]` *(Function)*: The function to customize cloning values.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `customizer`.
|
|
|
|
#### Returns
|
|
*(*)*: Returns the deep cloned value.
|
|
|
|
#### Example
|
|
```js
|
|
var users = [
|
|
{ 'user': 'barney' },
|
|
{ 'user': 'fred' }
|
|
];
|
|
|
|
var deep = _.cloneDeep(users);
|
|
deep[0] === users[0];
|
|
// => false
|
|
|
|
// using a customizer callback
|
|
var el = _.cloneDeep(document.body, function(value) {
|
|
if (_.isElement(value)) {
|
|
return value.cloneNode(true);
|
|
}
|
|
});
|
|
|
|
el === document.body
|
|
// => false
|
|
el.nodeName
|
|
// => BODY
|
|
el.childNodes.length;
|
|
// => 20
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_gtvalue-other"></a>`_.gt(value, other)`
|
|
<a href="#_gtvalue-other">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8581 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.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/blob/3.10.1/lodash.src.js#L8605 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.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`, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.gte(3, 1);
|
|
// => true
|
|
|
|
_.gte(3, 3);
|
|
// => true
|
|
|
|
_.gte(1, 3);
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isargumentsvalue"></a>`_.isArguments(value)`
|
|
<a href="#_isargumentsvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8625 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isarguments "See the npm package")
|
|
|
|
Checks if `value` is classified as an `arguments` object.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isArguments(function() { return arguments; }());
|
|
// => true
|
|
|
|
_.isArguments([1, 2, 3]);
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isarrayvalue"></a>`_.isArray(value)`
|
|
<a href="#_isarrayvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8646 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isarray "See the npm package")
|
|
|
|
Checks if `value` is classified as an `Array` object.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isArray([1, 2, 3]);
|
|
// => true
|
|
|
|
_.isArray(function() { return arguments; }());
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isbooleanvalue"></a>`_.isBoolean(value)`
|
|
<a href="#_isbooleanvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8666 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isboolean "See the npm package")
|
|
|
|
Checks if `value` is classified as a boolean primitive or object.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isBoolean(false);
|
|
// => true
|
|
|
|
_.isBoolean(null);
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isdatevalue"></a>`_.isDate(value)`
|
|
<a href="#_isdatevalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8686 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isdate "See the npm package")
|
|
|
|
Checks if `value` is classified as a `Date` object.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isDate(new Date);
|
|
// => true
|
|
|
|
_.isDate('Mon April 23 2012');
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_iselementvalue"></a>`_.isElement(value)`
|
|
<a href="#_iselementvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8706 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.iselement "See the npm package")
|
|
|
|
Checks if `value` is a DOM element.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is a DOM element, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isElement(document.body);
|
|
// => true
|
|
|
|
_.isElement('<body>');
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isemptyvalue"></a>`_.isEmpty(value)`
|
|
<a href="#_isemptyvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8737 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isempty "See the npm package")
|
|
|
|
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
|
|
greater than `0` or an object with own enumerable properties.
|
|
|
|
#### Arguments
|
|
1. `value` *(Array|Object|string)*: The value to inspect.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is empty, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isEmpty(null);
|
|
// => true
|
|
|
|
_.isEmpty(true);
|
|
// => true
|
|
|
|
_.isEmpty(1);
|
|
// => true
|
|
|
|
_.isEmpty([1, 2, 3]);
|
|
// => false
|
|
|
|
_.isEmpty({ 'a': 1 });
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isequalvalue-other-customizer-thisarg"></a>`_.isEqual(value, other, [customizer], [thisArg])`
|
|
<a href="#_isequalvalue-other-customizer-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8792 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isequal "See the npm package")
|
|
|
|
Performs a deep comparison between two values to determine if they are
|
|
equivalent. If `customizer` is provided it's invoked to compare values.
|
|
If `customizer` returns `undefined` comparisons are handled by the method
|
|
instead. The `customizer` is bound to `thisArg` and invoked with up to
|
|
three arguments: (value, other [, index|key]).
|
|
<br>
|
|
<br>
|
|
**Note:** This method supports comparing arrays, booleans, `Date` objects,
|
|
numbers, `Object` objects, regexes, and strings. Objects are compared by
|
|
their own, not inherited, enumerable properties. Functions and DOM nodes
|
|
are **not** supported. Provide a customizer function to extend support
|
|
for comparing other values.
|
|
|
|
#### Aliases
|
|
*_.eq*
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to compare.
|
|
2. `other` *(*)*: The other value to compare.
|
|
3. `[customizer]` *(Function)*: The function to customize value comparisons.
|
|
4. `[thisArg]` *(*)*: The `this` binding of `customizer`.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if the values are equivalent, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
var object = { 'user': 'fred' };
|
|
var other = { 'user': 'fred' };
|
|
|
|
object == other;
|
|
// => false
|
|
|
|
_.isEqual(object, other);
|
|
// => true
|
|
|
|
// using a customizer callback
|
|
var array = ['hello', 'goodbye'];
|
|
var other = ['hi', 'goodbye'];
|
|
|
|
_.isEqual(array, other, function(value, other) {
|
|
if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
|
|
return true;
|
|
}
|
|
});
|
|
// => true
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_iserrorvalue"></a>`_.isError(value)`
|
|
<a href="#_iserrorvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8815 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.iserror "See the npm package")
|
|
|
|
Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
|
|
`SyntaxError`, `TypeError`, or `URIError` object.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is an error object, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isError(new Error);
|
|
// => true
|
|
|
|
_.isError(Error);
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isfinitevalue"></a>`_.isFinite(value)`
|
|
<a href="#_isfinitevalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8846 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isfinite "See the npm package")
|
|
|
|
Checks if `value` is a finite primitive number.
|
|
<br>
|
|
<br>
|
|
**Note:** This method is based on [`Number.isFinite`](http://ecma-international.org/ecma-262/6.0/#sec-number.isfinite).
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is a finite number, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isFinite(10);
|
|
// => true
|
|
|
|
_.isFinite('10');
|
|
// => false
|
|
|
|
_.isFinite(true);
|
|
// => false
|
|
|
|
_.isFinite(Object(10));
|
|
// => false
|
|
|
|
_.isFinite(Infinity);
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isfunctionvalue"></a>`_.isFunction(value)`
|
|
<a href="#_isfunctionvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8866 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isfunction "See the npm package")
|
|
|
|
Checks if `value` is classified as a `Function` object.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isFunction(_);
|
|
// => true
|
|
|
|
_.isFunction(/abc/);
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_ismatchobject-source-customizer-thisarg"></a>`_.isMatch(object, source, [customizer], [thisArg])`
|
|
<a href="#_ismatchobject-source-customizer-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8939 "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
|
|
`object` contains equivalent property values. If `customizer` is provided
|
|
it's invoked to compare values. If `customizer` returns `undefined`
|
|
comparisons are handled by the method instead. The `customizer` is bound
|
|
to `thisArg` and invoked with three arguments: (value, other, index|key).
|
|
<br>
|
|
<br>
|
|
**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
|
|
1. `object` *(Object)*: The object to inspect.
|
|
2. `source` *(Object)*: The object of property values to match.
|
|
3. `[customizer]` *(Function)*: The function to customize value comparisons.
|
|
4. `[thisArg]` *(*)*: The `this` binding of `customizer`.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `object` is a match, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
var object = { 'user': 'fred', 'age': 40 };
|
|
|
|
_.isMatch(object, { 'age': 40 });
|
|
// => true
|
|
|
|
_.isMatch(object, { 'age': 36 });
|
|
// => false
|
|
|
|
// using a customizer callback
|
|
var object = { 'greeting': 'hello' };
|
|
var source = { 'greeting': 'hi' };
|
|
|
|
_.isMatch(object, source, function(value, other) {
|
|
return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
|
|
});
|
|
// => true
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isnanvalue"></a>`_.isNaN(value)`
|
|
<a href="#_isnanvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8969 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isnan "See the npm package")
|
|
|
|
Checks if `value` is `NaN`.
|
|
<br>
|
|
<br>
|
|
**Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
|
|
which returns `true` for `undefined` and other non-numeric values.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is `NaN`, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isNaN(NaN);
|
|
// => true
|
|
|
|
_.isNaN(new Number(NaN));
|
|
// => true
|
|
|
|
isNaN(undefined);
|
|
// => true
|
|
|
|
_.isNaN(undefined);
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isnativevalue"></a>`_.isNative(value)`
|
|
<a href="#_isnativevalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8991 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isnative "See the npm package")
|
|
|
|
Checks if `value` is a native function.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is a native function, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isNative(Array.prototype.push);
|
|
// => true
|
|
|
|
_.isNative(_);
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isnullvalue"></a>`_.isNull(value)`
|
|
<a href="#_isnullvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9017 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isnull "See the npm package")
|
|
|
|
Checks if `value` is `null`.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is `null`, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isNull(null);
|
|
// => true
|
|
|
|
_.isNull(void 0);
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isnumbervalue"></a>`_.isNumber(value)`
|
|
<a href="#_isnumbervalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9043 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isnumber "See the npm package")
|
|
|
|
Checks if `value` is classified as a `Number` primitive or object.
|
|
<br>
|
|
<br>
|
|
**Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
|
|
as numbers, use the `_.isFinite` method.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isNumber(8.4);
|
|
// => true
|
|
|
|
_.isNumber(NaN);
|
|
// => true
|
|
|
|
_.isNumber('8.4');
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isobjectvalue"></a>`_.isObject(value)`
|
|
<a href="#_isobjectvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L8893 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isobject "See the npm package")
|
|
|
|
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('')`)
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is an object, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isObject({});
|
|
// => true
|
|
|
|
_.isObject([1, 2, 3]);
|
|
// => true
|
|
|
|
_.isObject(1);
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isplainobjectvalue"></a>`_.isPlainObject(value)`
|
|
<a href="#_isplainobjectvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9077 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isplainobject "See the npm package")
|
|
|
|
Checks if `value` is a plain object, that is, an object created by the
|
|
`Object` constructor or one with a `[[Prototype]]` of `null`.
|
|
<br>
|
|
<br>
|
|
**Note:** This method assumes objects created by the `Object` constructor
|
|
have no inherited enumerable properties.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is a plain object, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
function Foo() {
|
|
this.a = 1;
|
|
}
|
|
|
|
_.isPlainObject(new Foo);
|
|
// => false
|
|
|
|
_.isPlainObject([1, 2, 3]);
|
|
// => false
|
|
|
|
_.isPlainObject({ 'x': 0, 'y': 0 });
|
|
// => true
|
|
|
|
_.isPlainObject(Object.create(null));
|
|
// => true
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isregexpvalue"></a>`_.isRegExp(value)`
|
|
<a href="#_isregexpvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9121 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isregexp "See the npm package")
|
|
|
|
Checks if `value` is classified as a `RegExp` object.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isRegExp(/abc/);
|
|
// => true
|
|
|
|
_.isRegExp('/abc/');
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isstringvalue"></a>`_.isString(value)`
|
|
<a href="#_isstringvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9141 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isstring "See the npm package")
|
|
|
|
Checks if `value` is classified as a `String` primitive or object.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isString('abc');
|
|
// => true
|
|
|
|
_.isString(1);
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_istypedarrayvalue"></a>`_.isTypedArray(value)`
|
|
<a href="#_istypedarrayvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9161 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.istypedarray "See the npm package")
|
|
|
|
Checks if `value` is classified as a typed array.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is correctly classified, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isTypedArray(new Uint8Array);
|
|
// => true
|
|
|
|
_.isTypedArray([]);
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_isundefinedvalue"></a>`_.isUndefined(value)`
|
|
<a href="#_isundefinedvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9181 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.isundefined "See the npm package")
|
|
|
|
Checks if `value` is `undefined`.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `value` is `undefined`, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.isUndefined(void 0);
|
|
// => true
|
|
|
|
_.isUndefined(null);
|
|
// => false
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_ltvalue-other"></a>`_.lt(value, other)`
|
|
<a href="#_ltvalue-other">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9205 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.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/blob/3.10.1/lodash.src.js#L9229 "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 href="#_toarrayvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9248 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.toarray "See the npm package")
|
|
|
|
Converts `value` to an array.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to convert.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the converted array.
|
|
|
|
#### Example
|
|
```js
|
|
(function() {
|
|
return _.toArray(arguments).slice(1);
|
|
}(1, 2, 3));
|
|
// => [2, 3]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_toplainobjectvalue"></a>`_.toPlainObject(value)`
|
|
<a href="#_toplainobjectvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9284 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.toplainobject "See the npm package")
|
|
|
|
Converts `value` to a plain object flattening inherited enumerable
|
|
properties of `value` to own properties of the plain object.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to convert.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the converted plain object.
|
|
|
|
#### Example
|
|
```js
|
|
function Foo() {
|
|
this.b = 2;
|
|
}
|
|
|
|
Foo.prototype.c = 3;
|
|
|
|
_.assign({ 'a': 1 }, new Foo);
|
|
// => { 'a': 1, 'b': 2 }
|
|
|
|
_.assign({ 'a': 1 }, _.toPlainObject(new Foo));
|
|
// => { 'a': 1, 'b': 2, 'c': 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/blob/3.10.1/lodash.src.js#L11803 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.add "See the npm package")
|
|
|
|
Adds two numbers.
|
|
|
|
#### Arguments
|
|
1. `augend` *(number)*: The first number to add.
|
|
2. `addend` *(number)*: The second number to add.
|
|
|
|
#### Returns
|
|
*(number)*: Returns the sum.
|
|
|
|
#### Example
|
|
```js
|
|
_.add(6, 4);
|
|
// => 10
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_ceiln-precision0"></a>`_.ceil(n, [precision=0])`
|
|
<a href="#_ceiln-precision0">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11827 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.ceil "See the npm package")
|
|
|
|
Calculates `n` rounded up to `precision`.
|
|
|
|
#### Arguments
|
|
1. `n` *(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="_floorn-precision0"></a>`_.floor(n, [precision=0])`
|
|
<a href="#_floorn-precision0">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11849 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.floor "See the npm package")
|
|
|
|
Calculates `n` rounded down to `precision`.
|
|
|
|
#### Arguments
|
|
1. `n` *(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="_maxcollection-iteratee-thisarg"></a>`_.max(collection, [iteratee], [thisArg])`
|
|
<a href="#_maxcollection-iteratee-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11898 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.max "See the npm package")
|
|
|
|
Gets the maximum value of `collection`. If `collection` is empty or falsey
|
|
`-Infinity` is returned. If an iteratee function is provided it's 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).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `iteratee` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
If an object is provided for `iteratee` 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.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(*)*: Returns the maximum value.
|
|
|
|
#### Example
|
|
```js
|
|
_.max([4, 2, 8, 6]);
|
|
// => 8
|
|
|
|
_.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/lodash/lodash/blob/3.10.1/lodash.src.js#L11947 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.min "See the npm package")
|
|
|
|
Gets the minimum value of `collection`. If `collection` is empty or falsey
|
|
`Infinity` is returned. If an iteratee function is provided it's 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).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `iteratee` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
If an object is provided for `iteratee` 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.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(*)*: Returns the minimum value.
|
|
|
|
#### Example
|
|
```js
|
|
_.min([4, 2, 8, 6]);
|
|
// => 2
|
|
|
|
_.min([]);
|
|
// => Infinity
|
|
|
|
var users = [
|
|
{ 'user': 'barney', 'age': 36 },
|
|
{ 'user': 'fred', 'age': 40 }
|
|
];
|
|
|
|
_.min(users, function(chr) {
|
|
return chr.age;
|
|
});
|
|
// => { 'user': 'barney', 'age': 36 }
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.min(users, 'age');
|
|
// => { 'user': 'barney', 'age': 36 }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_roundn-precision0"></a>`_.round(n, [precision=0])`
|
|
<a href="#_roundn-precision0">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11969 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.round "See the npm package")
|
|
|
|
Calculates `n` rounded to `precision`.
|
|
|
|
#### Arguments
|
|
1. `n` *(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="_sumcollection-iteratee-thisarg"></a>`_.sum(collection, [iteratee], [thisArg])`
|
|
<a href="#_sumcollection-iteratee-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L12003 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.sum "See the npm package")
|
|
|
|
Gets the sum of the values in `collection`.
|
|
|
|
#### Arguments
|
|
1. `collection` *(Array|Object|string)*: The collection to iterate over.
|
|
2. `[iteratee]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(number)*: Returns the sum.
|
|
|
|
#### Example
|
|
```js
|
|
_.sum([4, 6]);
|
|
// => 10
|
|
|
|
_.sum({ 'a': 4, 'b': 6 });
|
|
// => 10
|
|
|
|
var objects = [
|
|
{ 'n': 4 },
|
|
{ 'n': 6 }
|
|
];
|
|
|
|
_.sum(objects, function(object) {
|
|
return object.n;
|
|
});
|
|
// => 10
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.sum(objects, 'n');
|
|
// => 10
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `“Number” Methods`
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_inrangen-start0-end"></a>`_.inRange(n, [start=0], end)`
|
|
<a href="#_inrangen-start0-end">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10321 "View in source") [Ⓣ][1] [Ⓝ](https://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`.
|
|
|
|
#### Arguments
|
|
1. `n` *(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 `n` 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
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_randommin0-max1-floating"></a>`_.random([min=0], [max=1], [floating])`
|
|
<a href="#_randommin0-max1-floating">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10359 "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
|
|
argument is provided a number between `0` and the given number is returned.
|
|
If `floating` is `true`, or either `min` or `max` are floats, a floating-point
|
|
number is returned instead of an integer.
|
|
|
|
#### Arguments
|
|
1. `[min=0]` *(number)*: The minimum possible value.
|
|
2. `[max=1]` *(number)*: The maximum possible value.
|
|
3. `[floating]` *(boolean)*: Specify returning a floating-point number.
|
|
|
|
#### Returns
|
|
*(number)*: Returns the random number.
|
|
|
|
#### Example
|
|
```js
|
|
_.random(0, 5);
|
|
// => an integer between 0 and 5
|
|
|
|
_.random(5);
|
|
// => also an integer between 0 and 5
|
|
|
|
_.random(5, true);
|
|
// => a floating-point number between 0 and 5
|
|
|
|
_.random(1.2, 5.2);
|
|
// => a floating-point number between 1.2 and 5.2
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `“Object” Methods`
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_assignobject-sources-customizer-thisarg"></a>`_.assign(object, [sources], [customizer], [thisArg])`
|
|
<a href="#_assignobject-sources-customizer-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9372 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.assign "See the npm package")
|
|
|
|
Assigns own enumerable properties of source object(s) to the destination
|
|
object. Subsequent sources overwrite property assignments of previous sources.
|
|
If `customizer` is provided it's invoked to produce the assigned values.
|
|
The `customizer` is bound to `thisArg` and invoked with five arguments:<br>
|
|
(objectValue, sourceValue, key, object, source).
|
|
<br>
|
|
<br>
|
|
**Note:** This method mutates `object` and is based on
|
|
[`Object.assign`](http://ecma-international.org/ecma-262/6.0/#sec-object.assign).
|
|
|
|
#### Aliases
|
|
*_.extend*
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The destination object.
|
|
2. `[sources]` *(...Object)*: The source objects.
|
|
3. `[customizer]` *(Function)*: The function to customize assigned values.
|
|
4. `[thisArg]` *(*)*: The `this` binding of `customizer`.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns `object`.
|
|
|
|
#### Example
|
|
```js
|
|
_.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
|
|
// => { 'user': 'fred', 'age': 40 }
|
|
|
|
// using a customizer callback
|
|
var defaults = _.partialRight(_.assign, function(value, other) {
|
|
return _.isUndefined(value) ? other : value;
|
|
});
|
|
|
|
defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
|
|
// => { 'user': 'barney', 'age': 36 }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_createprototype-properties"></a>`_.create(prototype, [properties])`
|
|
<a href="#_createprototype-properties">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9412 "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
|
|
`properties` object is provided its own enumerable properties are assigned
|
|
to the created object.
|
|
|
|
#### Arguments
|
|
1. `prototype` *(Object)*: The object to inherit from.
|
|
2. `[properties]` *(Object)*: The properties to assign to the object.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the new object.
|
|
|
|
#### Example
|
|
```js
|
|
function Shape() {
|
|
this.x = 0;
|
|
this.y = 0;
|
|
}
|
|
|
|
function Circle() {
|
|
Shape.call(this);
|
|
}
|
|
|
|
Circle.prototype = _.create(Shape.prototype, {
|
|
'constructor': Circle
|
|
});
|
|
|
|
var circle = new Circle;
|
|
circle instanceof Circle;
|
|
// => true
|
|
|
|
circle instanceof Shape;
|
|
// => true
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_defaultsobject-sources"></a>`_.defaults(object, [sources])`
|
|
<a href="#_defaultsobject-sources">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9438 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.defaults "See the npm package")
|
|
|
|
Assigns own enumerable properties of source object(s) to the destination
|
|
object for all destination properties that resolve to `undefined`. Once a
|
|
property is set, additional values of the same property are ignored.
|
|
<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
|
|
_.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
|
|
// => { 'user': 'barney', 'age': 36 }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_defaultsdeepobject-sources"></a>`_.defaultsDeep(object, [sources])`
|
|
<a href="#_defaultsdeepobject-sources">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9458 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.defaultsdeep "See the npm package")
|
|
|
|
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', 'age': 36 } });
|
|
// => { 'user': { 'name': 'barney', 'age': 36 } }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_findkeyobject-predicate_identity-thisarg"></a>`_.findKey(object, [predicate=_.identity], [thisArg])`
|
|
<a href="#_findkeyobject-predicate_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9508 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.findkey "See the npm package")
|
|
|
|
This method is like `_.find` except that it returns the key of the first
|
|
element `predicate` returns truthy for instead of the element itself.
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `predicate` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
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. `object` *(Object)*: The object to search.
|
|
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(string|undefined)*: Returns the key of the matched element, else `undefined`.
|
|
|
|
#### Example
|
|
```js
|
|
var users = {
|
|
'barney': { 'age': 36, 'active': true },
|
|
'fred': { 'age': 40, 'active': false },
|
|
'pebbles': { 'age': 1, 'active': true }
|
|
};
|
|
|
|
_.findKey(users, function(chr) {
|
|
return chr.age < 40;
|
|
});
|
|
// => 'barney' (iteration order is not guaranteed)
|
|
|
|
// using the `_.matches` callback shorthand
|
|
_.findKey(users, { 'age': 1, 'active': true });
|
|
// => 'pebbles'
|
|
|
|
// using the `_.matchesProperty` callback shorthand
|
|
_.findKey(users, 'active', false);
|
|
// => 'fred'
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.findKey(users, 'active');
|
|
// => 'barney'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_findlastkeyobject-predicate_identity-thisarg"></a>`_.findLastKey(object, [predicate=_.identity], [thisArg])`
|
|
<a href="#_findlastkeyobject-predicate_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9558 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.findlastkey "See the npm package")
|
|
|
|
This method is like `_.findKey` except that it iterates over elements of
|
|
a collection in the opposite order.
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `predicate` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
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. `object` *(Object)*: The object to search.
|
|
2. `[predicate=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(string|undefined)*: Returns the key of the matched element, else `undefined`.
|
|
|
|
#### Example
|
|
```js
|
|
var users = {
|
|
'barney': { 'age': 36, 'active': true },
|
|
'fred': { 'age': 40, 'active': false },
|
|
'pebbles': { 'age': 1, 'active': true }
|
|
};
|
|
|
|
_.findLastKey(users, function(chr) {
|
|
return chr.age < 40;
|
|
});
|
|
// => returns `pebbles` assuming `_.findKey` returns `barney`
|
|
|
|
// using the `_.matches` callback shorthand
|
|
_.findLastKey(users, { 'age': 36, 'active': true });
|
|
// => 'barney'
|
|
|
|
// using the `_.matchesProperty` callback shorthand
|
|
_.findLastKey(users, 'active', false);
|
|
// => 'fred'
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.findLastKey(users, 'active');
|
|
// => 'pebbles'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_forinobject-iteratee_identity-thisarg"></a>`_.forIn(object, [iteratee=_.identity], [thisArg])`
|
|
<a href="#_forinobject-iteratee_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9587 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.forin "See the npm package")
|
|
|
|
Iterates over own and inherited enumerable properties of an object invoking
|
|
`iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
|
|
with three arguments: (value, key, object). Iteratee functions may exit
|
|
iteration early by explicitly returning `false`.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to iterate over.
|
|
2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns `object`.
|
|
|
|
#### Example
|
|
```js
|
|
function Foo() {
|
|
this.a = 1;
|
|
this.b = 2;
|
|
}
|
|
|
|
Foo.prototype.c = 3;
|
|
|
|
_.forIn(new Foo, function(value, key) {
|
|
console.log(key);
|
|
});
|
|
// => logs 'a', 'b', and 'c' (iteration order is not guaranteed)
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_forinrightobject-iteratee_identity-thisarg"></a>`_.forInRight(object, [iteratee=_.identity], [thisArg])`
|
|
<a href="#_forinrightobject-iteratee_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9614 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.forinright "See the npm package")
|
|
|
|
This method is like `_.forIn` except that it iterates over properties of
|
|
`object` in the opposite order.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to iterate over.
|
|
2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns `object`.
|
|
|
|
#### Example
|
|
```js
|
|
function Foo() {
|
|
this.a = 1;
|
|
this.b = 2;
|
|
}
|
|
|
|
Foo.prototype.c = 3;
|
|
|
|
_.forInRight(new Foo, function(value, key) {
|
|
console.log(key);
|
|
});
|
|
// => logs 'c', 'b', and 'a' assuming `_.forIn ` logs 'a', 'b', and 'c'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_forownobject-iteratee_identity-thisarg"></a>`_.forOwn(object, [iteratee=_.identity], [thisArg])`
|
|
<a href="#_forownobject-iteratee_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9643 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.forown "See the npm package")
|
|
|
|
Iterates over own enumerable properties of an object invoking `iteratee`
|
|
for each property. The `iteratee` is bound to `thisArg` and invoked with
|
|
three arguments: (value, key, object). Iteratee functions may exit iteration
|
|
early by explicitly returning `false`.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to iterate over.
|
|
2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns `object`.
|
|
|
|
#### Example
|
|
```js
|
|
function Foo() {
|
|
this.a = 1;
|
|
this.b = 2;
|
|
}
|
|
|
|
Foo.prototype.c = 3;
|
|
|
|
_.forOwn(new Foo, function(value, key) {
|
|
console.log(key);
|
|
});
|
|
// => logs 'a' and 'b' (iteration order is not guaranteed)
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_forownrightobject-iteratee_identity-thisarg"></a>`_.forOwnRight(object, [iteratee=_.identity], [thisArg])`
|
|
<a href="#_forownrightobject-iteratee_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9670 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.forownright "See the npm package")
|
|
|
|
This method is like `_.forOwn` except that it iterates over properties of
|
|
`object` in the opposite order.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to iterate over.
|
|
2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns `object`.
|
|
|
|
#### Example
|
|
```js
|
|
function Foo() {
|
|
this.a = 1;
|
|
this.b = 2;
|
|
}
|
|
|
|
Foo.prototype.c = 3;
|
|
|
|
_.forOwnRight(new Foo, function(value, key) {
|
|
console.log(key);
|
|
});
|
|
// => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_functionsobject"></a>`_.functions(object)`
|
|
<a href="#_functionsobject">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9687 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.functions "See the npm package")
|
|
|
|
Creates an array of function property names from all enumerable properties,
|
|
own and inherited, of `object`.
|
|
|
|
#### Aliases
|
|
*_.methods*
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to inspect.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array of property names.
|
|
|
|
#### Example
|
|
```js
|
|
_.functions(_);
|
|
// => ['after', 'ary', 'assign', ...]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_getobject-path-defaultvalue"></a>`_.get(object, path, [defaultValue])`
|
|
<a href="#_getobject-path-defaultvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9715 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.get "See the npm package")
|
|
|
|
Gets the property value at `path` of `object`. If the resolved value is
|
|
`undefined` the `defaultValue` is used in its place.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to query.
|
|
2. `path` *(Array|string)*: The path of the property to get.
|
|
3. `[defaultValue]` *(*)*: The value returned if the resolved value is `undefined`.
|
|
|
|
#### Returns
|
|
*(*)*: Returns the resolved value.
|
|
|
|
#### Example
|
|
```js
|
|
var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
|
|
|
_.get(object, 'a[0].b.c');
|
|
// => 3
|
|
|
|
_.get(object, ['a', '0', 'b', 'c']);
|
|
// => 3
|
|
|
|
_.get(object, 'a.b.c', 'default');
|
|
// => 'default'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_hasobject-path"></a>`_.has(object, path)`
|
|
<a href="#_hasobject-path">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9742 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.has "See the npm package")
|
|
|
|
Checks if `path` is a direct property.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to query.
|
|
2. `path` *(Array|string)*: The path to check.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `path` is a direct property, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
var object = { 'a': { 'b': { 'c': 3 } } };
|
|
|
|
_.has(object, 'a');
|
|
// => true
|
|
|
|
_.has(object, 'a.b.c');
|
|
// => true
|
|
|
|
_.has(object, ['a', 'b', 'c']);
|
|
// => true
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_invertobject-multivalue"></a>`_.invert(object, [multiValue])`
|
|
<a href="#_invertobject-multivalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9783 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.invert "See the npm package")
|
|
|
|
Creates an object composed of the inverted keys and values of `object`.
|
|
If `object` contains duplicate values, subsequent values overwrite property
|
|
assignments of previous values unless `multiValue` is `true`.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to invert.
|
|
2. `[multiValue]` *(boolean)*: Allow multiple values per key.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the new inverted object.
|
|
|
|
#### Example
|
|
```js
|
|
var object = { 'a': 1, 'b': 2, 'c': 1 };
|
|
|
|
_.invert(object);
|
|
// => { '1': 'c', '2': 'b' }
|
|
|
|
// with `multiValue`
|
|
_.invert(object, true);
|
|
// => { '1': ['a', 'c'], '2': ['b'] }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_keysobject"></a>`_.keys(object)`
|
|
<a href="#_keysobject">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9837 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.keys "See the npm package")
|
|
|
|
Creates an array of the own enumerable property names of `object`.
|
|
<br>
|
|
<br>
|
|
**Note:** Non-object values are coerced to objects. See the
|
|
[ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
|
|
for more details.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to query.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the array of property names.
|
|
|
|
#### Example
|
|
```js
|
|
function Foo() {
|
|
this.a = 1;
|
|
this.b = 2;
|
|
}
|
|
|
|
Foo.prototype.c = 3;
|
|
|
|
_.keys(new Foo);
|
|
// => ['a', 'b'] (iteration order is not guaranteed)
|
|
|
|
_.keys('hi');
|
|
// => ['0', '1']
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_keysinobject"></a>`_.keysIn(object)`
|
|
<a href="#_keysinobject">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9868 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.keysin "See the npm package")
|
|
|
|
Creates an array of the own and inherited enumerable property names of `object`.
|
|
<br>
|
|
<br>
|
|
**Note:** Non-object values are coerced to objects.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to query.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the array of property names.
|
|
|
|
#### Example
|
|
```js
|
|
function Foo() {
|
|
this.a = 1;
|
|
this.b = 2;
|
|
}
|
|
|
|
Foo.prototype.c = 3;
|
|
|
|
_.keysIn(new Foo);
|
|
// => ['a', 'b', 'c'] (iteration order is not guaranteed)
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_mapkeysobject-iteratee_identity-thisarg"></a>`_.mapKeys(object, [iteratee=_.identity], [thisArg])`
|
|
<a href="#_mapkeysobject-iteratee_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9945 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.mapkeys "See the npm package")
|
|
|
|
The opposite of `_.mapValues`; this method creates an object with the
|
|
same values as `object` and keys generated by running each own enumerable
|
|
property of `object` through `iteratee`.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to iterate over.
|
|
2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the new mapped object.
|
|
|
|
#### Example
|
|
```js
|
|
_.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
|
|
return key + value;
|
|
});
|
|
// => { 'a1': 1, 'b2': 2 }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_mapvaluesobject-iteratee_identity-thisarg"></a>`_.mapValues(object, [iteratee=_.identity], [thisArg])`
|
|
<a href="#_mapvaluesobject-iteratee_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9988 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.mapvalues "See the npm package")
|
|
|
|
Creates an object with the same keys as `object` and values generated by
|
|
running each own enumerable property of `object` through `iteratee`. The
|
|
iteratee function is bound to `thisArg` and invoked with three arguments:<br>
|
|
(value, key, object).
|
|
<br>
|
|
<br>
|
|
If a property name is provided for `iteratee` the created `_.property`
|
|
style callback returns the property value of the given element.
|
|
<br>
|
|
<br>
|
|
If a value is also provided for `thisArg` the created `_.matchesProperty`
|
|
style callback returns `true` for elements that have a matching property
|
|
value, else `false`.
|
|
<br>
|
|
<br>
|
|
If an object is provided for `iteratee` the created `_.matches` style
|
|
callback returns `true` for elements that have the properties of the given
|
|
object, else `false`.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to iterate over.
|
|
2. `[iteratee=_.identity]` *(Function|Object|string)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the new mapped object.
|
|
|
|
#### Example
|
|
```js
|
|
_.mapValues({ 'a': 1, 'b': 2 }, function(n) {
|
|
return n * 3;
|
|
});
|
|
// => { 'a': 3, 'b': 6 }
|
|
|
|
var users = {
|
|
'fred': { 'user': 'fred', 'age': 40 },
|
|
'pebbles': { 'user': 'pebbles', 'age': 1 }
|
|
};
|
|
|
|
// using the `_.property` callback shorthand
|
|
_.mapValues(users, 'age');
|
|
// => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_mergeobject-sources-customizer-thisarg"></a>`_.merge(object, [sources], [customizer], [thisArg])`
|
|
<a href="#_mergeobject-sources-customizer-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L9338 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.merge "See the npm package")
|
|
|
|
Recursively merges own enumerable properties of the source object(s), that
|
|
don't resolve to `undefined` into the destination object. Subsequent sources
|
|
overwrite property assignments of previous sources. If `customizer` is
|
|
provided it's invoked to produce the merged values of the destination and
|
|
source properties. If `customizer` returns `undefined` merging is handled
|
|
by the method instead. The `customizer` is bound to `thisArg` and invoked
|
|
with five arguments: (objectValue, sourceValue, key, object, source).
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The destination object.
|
|
2. `[sources]` *(...Object)*: The source objects.
|
|
3. `[customizer]` *(Function)*: The function to customize assigned values.
|
|
4. `[thisArg]` *(*)*: The `this` binding of `customizer`.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns `object`.
|
|
|
|
#### Example
|
|
```js
|
|
var users = {
|
|
'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
|
|
};
|
|
|
|
var ages = {
|
|
'data': [{ 'age': 36 }, { 'age': 40 }]
|
|
};
|
|
|
|
_.merge(users, ages);
|
|
// => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
|
|
|
|
// using a customizer callback
|
|
var object = {
|
|
'fruits': ['apple'],
|
|
'vegetables': ['beet']
|
|
};
|
|
|
|
var other = {
|
|
'fruits': ['banana'],
|
|
'vegetables': ['carrot']
|
|
};
|
|
|
|
_.merge(object, other, function(a, b) {
|
|
if (_.isArray(a)) {
|
|
return a.concat(b);
|
|
}
|
|
});
|
|
// => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_omitobject-predicate-thisarg"></a>`_.omit(object, [predicate], [thisArg])`
|
|
<a href="#_omitobject-predicate-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10013 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.omit "See the npm package")
|
|
|
|
The opposite of `_.pick`; this method creates an object composed of the
|
|
own and inherited enumerable properties of `object` that are not omitted.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The source object.
|
|
2. `[predicate]` *(Function|...(string|string[])*: The function invoked per iteration or property names to omit, specified as individual property names or arrays of property names.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the new object.
|
|
|
|
#### Example
|
|
```js
|
|
var object = { 'user': 'fred', 'age': 40 };
|
|
|
|
_.omit(object, 'age');
|
|
// => { 'user': 'fred' }
|
|
|
|
_.omit(object, _.isNumber);
|
|
// => { 'user': 'fred' }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_pairsobject"></a>`_.pairs(object)`
|
|
<a href="#_pairsobject">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10041 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.pairs "See the npm package")
|
|
|
|
Creates a two dimensional array of the key-value pairs for `object`,
|
|
e.g. `[[key1, value1], [key2, value2]]`.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to query.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array of key-value pairs.
|
|
|
|
#### Example
|
|
```js
|
|
_.pairs({ 'barney': 36, 'fred': 40 });
|
|
// => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_pickobject-predicate-thisarg"></a>`_.pick(object, [predicate], [thisArg])`
|
|
<a href="#_pickobject-predicate-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10082 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.pick "See the npm package")
|
|
|
|
Creates an object composed of the picked `object` properties. Property
|
|
names may be specified as individual arguments or as arrays of property
|
|
names. If `predicate` is provided it's invoked for each property of `object`
|
|
picking the properties `predicate` returns truthy for. The predicate is
|
|
bound to `thisArg` and invoked with three arguments: (value, key, object).
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The source object.
|
|
2. `[predicate]` *(Function|...(string|string[])*: The function invoked per iteration or property names to pick, specified as individual property names or arrays of property names.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `predicate`.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns the new object.
|
|
|
|
#### Example
|
|
```js
|
|
var object = { 'user': 'fred', 'age': 40 };
|
|
|
|
_.pick(object, 'user');
|
|
// => { 'user': 'fred' }
|
|
|
|
_.pick(object, _.isString);
|
|
// => { 'user': 'fred' }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_resultobject-path-defaultvalue"></a>`_.result(object, path, [defaultValue])`
|
|
<a href="#_resultobject-path-defaultvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10119 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.result "See the npm package")
|
|
|
|
This method is like `_.get` except that if the resolved value is a function
|
|
it's invoked with the `this` binding of its parent object and its result
|
|
is returned.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to query.
|
|
2. `path` *(Array|string)*: The path of the property to resolve.
|
|
3. `[defaultValue]` *(*)*: The value returned if the resolved value is `undefined`.
|
|
|
|
#### Returns
|
|
*(*)*: Returns the resolved value.
|
|
|
|
#### Example
|
|
```js
|
|
var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
|
|
|
|
_.result(object, 'a[0].b.c1');
|
|
// => 3
|
|
|
|
_.result(object, 'a[0].b.c2');
|
|
// => 4
|
|
|
|
_.result(object, 'a.b.c', 'default');
|
|
// => 'default'
|
|
|
|
_.result(object, 'a.b.c', _.constant('default'));
|
|
// => 'default'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_setobject-path-value"></a>`_.set(object, path, value)`
|
|
<a href="#_setobject-path-value">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10155 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.set "See the npm package")
|
|
|
|
Sets the property value of `path` on `object`. If a portion of `path`
|
|
does not exist it's created.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to augment.
|
|
2. `path` *(Array|string)*: The path of the property to set.
|
|
3. `value` *(*)*: The value to set.
|
|
|
|
#### Returns
|
|
*(Object)*: Returns `object`.
|
|
|
|
#### Example
|
|
```js
|
|
var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
|
|
|
_.set(object, 'a[0].b.c', 4);
|
|
console.log(object.a[0].b.c);
|
|
// => 4
|
|
|
|
_.set(object, 'x[0].y.z', 5);
|
|
console.log(object.x[0].y.z);
|
|
// => 5
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_transformobject-iteratee_identity-accumulator-thisarg"></a>`_.transform(object, [iteratee=_.identity], [accumulator], [thisArg])`
|
|
<a href="#_transformobject-iteratee_identity-accumulator-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10210 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.transform "See the npm package")
|
|
|
|
An alternative to `_.reduce`; this method transforms `object` to a new
|
|
`accumulator` object which is the result of running each of its own enumerable
|
|
properties through `iteratee`, with each invocation potentially mutating
|
|
the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
|
|
with four arguments: (accumulator, value, key, object). Iteratee functions
|
|
may exit iteration early by explicitly returning `false`.
|
|
|
|
#### Arguments
|
|
1. `object` *(Array|Object)*: The object to iterate over.
|
|
2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration.
|
|
3. `[accumulator]` *(*)*: The custom accumulator value.
|
|
4. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(*)*: Returns the accumulated value.
|
|
|
|
#### Example
|
|
```js
|
|
_.transform([2, 3, 4], function(result, n) {
|
|
result.push(n *= n);
|
|
return n % 2 == 0;
|
|
});
|
|
// => [4, 9]
|
|
|
|
_.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
|
|
result[key] = n * 3;
|
|
});
|
|
// => { 'a': 3, 'b': 6 }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_valuesobject"></a>`_.values(object)`
|
|
<a href="#_valuesobject">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10257 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.values "See the npm package")
|
|
|
|
Creates an array of the own enumerable property values of `object`.
|
|
<br>
|
|
<br>
|
|
**Note:** Non-object values are coerced to objects.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to query.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the array of property values.
|
|
|
|
#### Example
|
|
```js
|
|
function Foo() {
|
|
this.a = 1;
|
|
this.b = 2;
|
|
}
|
|
|
|
Foo.prototype.c = 3;
|
|
|
|
_.values(new Foo);
|
|
// => [1, 2] (iteration order is not guaranteed)
|
|
|
|
_.values('hi');
|
|
// => ['h', 'i']
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_valuesinobject"></a>`_.valuesIn(object)`
|
|
<a href="#_valuesinobject">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10284 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.valuesin "See the npm package")
|
|
|
|
Creates an array of the own and inherited enumerable property values
|
|
of `object`.
|
|
<br>
|
|
<br>
|
|
**Note:** Non-object values are coerced to objects.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to query.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the array of property values.
|
|
|
|
#### Example
|
|
```js
|
|
function Foo() {
|
|
this.a = 1;
|
|
this.b = 2;
|
|
}
|
|
|
|
Foo.prototype.c = 3;
|
|
|
|
_.valuesIn(new Foo);
|
|
// => [1, 2, 3] (iteration order is not guaranteed)
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `“String” Methods`
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_camelcasestring"></a>`_.camelCase([string=''])`
|
|
<a href="#_camelcasestring">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10415 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.camelcase "See the npm package")
|
|
|
|
Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to convert.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the camel cased string.
|
|
|
|
#### Example
|
|
```js
|
|
_.camelCase('Foo Bar');
|
|
// => 'fooBar'
|
|
|
|
_.camelCase('--foo-bar');
|
|
// => 'fooBar'
|
|
|
|
_.camelCase('__foo_bar__');
|
|
// => 'fooBar'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_capitalizestring"></a>`_.capitalize([string=''])`
|
|
<a href="#_capitalizestring">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10433 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.capitalize "See the npm package")
|
|
|
|
Capitalizes the first character of `string`.
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to capitalize.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the capitalized string.
|
|
|
|
#### Example
|
|
```js
|
|
_.capitalize('fred');
|
|
// => 'Fred'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_deburrstring"></a>`_.deburr([string=''])`
|
|
<a href="#_deburrstring">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10452 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.deburr "See the npm package")
|
|
|
|
Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
|
|
to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to deburr.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the deburred string.
|
|
|
|
#### Example
|
|
```js
|
|
_.deburr('déjà vu');
|
|
// => 'deja vu'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_endswithstring-target-positionstringlength"></a>`_.endsWith([string=''], [target], [position=string.length])`
|
|
<a href="#_endswithstring-target-positionstringlength">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10478 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.endswith "See the npm package")
|
|
|
|
Checks if `string` ends with the given target string.
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to search.
|
|
2. `[target]` *(string)*: The string to search for.
|
|
3. `[position=string.length]` *(number)*: The position to search from.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `string` ends with `target`, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.endsWith('abc', 'c');
|
|
// => true
|
|
|
|
_.endsWith('abc', 'b');
|
|
// => false
|
|
|
|
_.endsWith('abc', 'b', 2);
|
|
// => true
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_escapestring"></a>`_.escape([string=''])`
|
|
<a href="#_escapestring">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10523 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.escape "See the npm package")
|
|
|
|
Converts the characters "&", "<", ">", '"', "'", and "\`", in `string` to
|
|
their corresponding HTML entities.
|
|
<br>
|
|
<br>
|
|
**Note:** No other characters are escaped. To escape additional characters
|
|
use a third-party library like [_he_](https://mths.be/he).
|
|
<br>
|
|
<br>
|
|
Though the ">" character is escaped for symmetry, characters like
|
|
">" and "/" don't need escaping in HTML and have no special meaning
|
|
unless they're part of a tag or unquoted attribute value.
|
|
See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
|
|
(under "semi-related fun fact") for more details.
|
|
<br>
|
|
<br>
|
|
Backticks are escaped because in Internet Explorer < 9, they can break out
|
|
of attribute values or HTML comments. See [#59](https://html5sec.org/#59),
|
|
[#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
|
|
[#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
|
|
for more details.
|
|
<br>
|
|
<br>
|
|
When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
|
|
to reduce XSS vectors.
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to escape.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the escaped string.
|
|
|
|
#### Example
|
|
```js
|
|
_.escape('fred, barney, & pebbles');
|
|
// => 'fred, barney, & pebbles'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_escaperegexpstring"></a>`_.escapeRegExp([string=''])`
|
|
<a href="#_escaperegexpstring">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10545 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.escaperegexp "See the npm package")
|
|
|
|
Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
|
|
"*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to escape.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the escaped string.
|
|
|
|
#### Example
|
|
```js
|
|
_.escapeRegExp('[lodash](https://lodash.com/)');
|
|
// => '\[lodash\]\(https:\/\/lodash\.com\/\)'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_kebabcasestring"></a>`_.kebabCase([string=''])`
|
|
<a href="#_kebabcasestring">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10571 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.kebabcase "See the npm package")
|
|
|
|
Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to convert.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the kebab cased string.
|
|
|
|
#### Example
|
|
```js
|
|
_.kebabCase('Foo Bar');
|
|
// => 'foo-bar'
|
|
|
|
_.kebabCase('fooBar');
|
|
// => 'foo-bar'
|
|
|
|
_.kebabCase('__foo_bar__');
|
|
// => 'foo-bar'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_padstring-length0-chars"></a>`_.pad([string=''], [length=0], [chars=' '])`
|
|
<a href="#_padstring-length0-chars">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10597 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.pad "See the npm package")
|
|
|
|
Pads `string` on the left and right sides if it's shorter than `length`.
|
|
Padding characters are truncated if they can't be evenly divided by `length`.
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to pad.
|
|
2. `[length=0]` *(number)*: The padding length.
|
|
3. `[chars=' ']` *(string)*: The string used as padding.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the padded string.
|
|
|
|
#### Example
|
|
```js
|
|
_.pad('abc', 8);
|
|
// => ' abc '
|
|
|
|
_.pad('abc', 8, '_-');
|
|
// => '_-abc_-_'
|
|
|
|
_.pad('abc', 3);
|
|
// => 'abc'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_padleftstring-length0-chars"></a>`_.padLeft([string=''], [length=0], [chars=' '])`
|
|
<a href="#_padleftstring-length0-chars">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10635 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.padleft "See the npm package")
|
|
|
|
Pads `string` on the left side if it's shorter than `length`. Padding
|
|
characters are truncated if they exceed `length`.
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to pad.
|
|
2. `[length=0]` *(number)*: The padding length.
|
|
3. `[chars=' ']` *(string)*: The string used as padding.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the padded string.
|
|
|
|
#### Example
|
|
```js
|
|
_.padLeft('abc', 6);
|
|
// => ' abc'
|
|
|
|
_.padLeft('abc', 6, '_-');
|
|
// => '_-_abc'
|
|
|
|
_.padLeft('abc', 3);
|
|
// => 'abc'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_padrightstring-length0-chars"></a>`_.padRight([string=''], [length=0], [chars=' '])`
|
|
<a href="#_padrightstring-length0-chars">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10659 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.padright "See the npm package")
|
|
|
|
Pads `string` on the right side if it's shorter than `length`. Padding
|
|
characters are truncated if they exceed `length`.
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to pad.
|
|
2. `[length=0]` *(number)*: The padding length.
|
|
3. `[chars=' ']` *(string)*: The string used as padding.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the padded string.
|
|
|
|
#### Example
|
|
```js
|
|
_.padRight('abc', 6);
|
|
// => 'abc '
|
|
|
|
_.padRight('abc', 6, '_-');
|
|
// => 'abc_-_'
|
|
|
|
_.padRight('abc', 3);
|
|
// => 'abc'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_parseintstring-radix"></a>`_.parseInt(string, [radix])`
|
|
<a href="#_parseintstring-radix">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10684 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.parseint "See the npm package")
|
|
|
|
Converts `string` to an integer of the specified radix. If `radix` is
|
|
`undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
|
|
in which case a `radix` of `16` is used.
|
|
<br>
|
|
<br>
|
|
**Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)
|
|
of `parseInt`.
|
|
|
|
#### Arguments
|
|
1. `string` *(string)*: The string to convert.
|
|
2. `[radix]` *(number)*: The radix to interpret `value` by.
|
|
|
|
#### Returns
|
|
*(number)*: Returns the converted integer.
|
|
|
|
#### Example
|
|
```js
|
|
_.parseInt('08');
|
|
// => 8
|
|
|
|
_.map(['6', '08', '10'], _.parseInt);
|
|
// => [6, 8, 10]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_repeatstring-n0"></a>`_.repeat([string=''], [n=0])`
|
|
<a href="#_repeatstring-n0">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10717 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.repeat "See the npm package")
|
|
|
|
Repeats the given string `n` times.
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to repeat.
|
|
2. `[n=0]` *(number)*: The number of times to repeat the string.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the repeated string.
|
|
|
|
#### Example
|
|
```js
|
|
_.repeat('*', 3);
|
|
// => '***'
|
|
|
|
_.repeat('abc', 2);
|
|
// => 'abcabc'
|
|
|
|
_.repeat('abc', 0);
|
|
// => ''
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_snakecasestring"></a>`_.snakeCase([string=''])`
|
|
<a href="#_snakecasestring">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10756 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.snakecase "See the npm package")
|
|
|
|
Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to convert.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the snake cased string.
|
|
|
|
#### Example
|
|
```js
|
|
_.snakeCase('Foo Bar');
|
|
// => 'foo_bar'
|
|
|
|
_.snakeCase('fooBar');
|
|
// => 'foo_bar'
|
|
|
|
_.snakeCase('--foo-bar');
|
|
// => 'foo_bar'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_startcasestring"></a>`_.startCase([string=''])`
|
|
<a href="#_startcasestring">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10779 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.startcase "See the npm package")
|
|
|
|
Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to convert.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the start cased string.
|
|
|
|
#### Example
|
|
```js
|
|
_.startCase('--foo-bar');
|
|
// => 'Foo Bar'
|
|
|
|
_.startCase('fooBar');
|
|
// => 'Foo Bar'
|
|
|
|
_.startCase('__foo_bar__');
|
|
// => 'Foo Bar'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_startswithstring-target-position0"></a>`_.startsWith([string=''], [target], [position=0])`
|
|
<a href="#_startswithstring-target-position0">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10804 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.startswith "See the npm package")
|
|
|
|
Checks if `string` starts with the given target string.
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to search.
|
|
2. `[target]` *(string)*: The string to search for.
|
|
3. `[position=0]` *(number)*: The position to search from.
|
|
|
|
#### Returns
|
|
*(boolean)*: Returns `true` if `string` starts with `target`, else `false`.
|
|
|
|
#### Example
|
|
```js
|
|
_.startsWith('abc', 'a');
|
|
// => true
|
|
|
|
_.startsWith('abc', 'b');
|
|
// => false
|
|
|
|
_.startsWith('abc', 'b', 1);
|
|
// => true
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_templatestring-options"></a>`_.template([string=''], [options])`
|
|
<a href="#_templatestring-options">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L10909 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.template "See the npm package")
|
|
|
|
Creates a compiled template function that can interpolate data properties
|
|
in "interpolate" delimiters, HTML-escape interpolated data properties in
|
|
"escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
|
|
properties may be accessed as free variables in the template. If a setting
|
|
object is provided it takes precedence over `_.templateSettings` values.
|
|
<br>
|
|
<br>
|
|
**Note:** In the development build `_.template` utilizes
|
|
[sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
|
|
for easier debugging.
|
|
<br>
|
|
<br>
|
|
For more information on precompiling templates see
|
|
[lodash's custom builds documentation](https://lodash.com/custom-builds).
|
|
<br>
|
|
<br>
|
|
For more information on Chrome extension sandboxes see
|
|
[Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The template string.
|
|
2. `[options]` *(Object)*: The options object.
|
|
3. `[options.escape]` *(RegExp)*: The HTML "escape" delimiter.
|
|
4. `[options.evaluate]` *(RegExp)*: The "evaluate" delimiter.
|
|
5. `[options.imports]` *(Object)*: An object to import into the template as free variables.
|
|
6. `[options.interpolate]` *(RegExp)*: The "interpolate" delimiter.
|
|
7. `[options.sourceURL]` *(string)*: The sourceURL of the template's compiled source.
|
|
8. `[options.variable]` *(string)*: The data object variable name.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the compiled template function.
|
|
|
|
#### Example
|
|
```js
|
|
// using the "interpolate" delimiter to create a compiled template
|
|
var compiled = _.template('hello <%= user %>!');
|
|
compiled({ 'user': 'fred' });
|
|
// => 'hello fred!'
|
|
|
|
// using the HTML "escape" delimiter to escape data property values
|
|
var compiled = _.template('<b><%- value %></b>');
|
|
compiled({ 'value': '<script>' });
|
|
// => '<b><script></b>'
|
|
|
|
// using the "evaluate" delimiter to execute JavaScript and generate HTML
|
|
var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
|
|
compiled({ 'users': ['fred', 'barney'] });
|
|
// => '<li>fred</li><li>barney</li>'
|
|
|
|
// using the internal `print` function in "evaluate" delimiters
|
|
var compiled = _.template('<% print("hello " + user); %>!');
|
|
compiled({ 'user': 'barney' });
|
|
// => 'hello barney!'
|
|
|
|
// using the ES delimiter as an alternative to the default "interpolate" delimiter
|
|
var compiled = _.template('hello ${ user }!');
|
|
compiled({ 'user': 'pebbles' });
|
|
// => 'hello pebbles!'
|
|
|
|
// using custom template delimiters
|
|
_.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
|
|
var compiled = _.template('hello {{ user }}!');
|
|
compiled({ 'user': 'mustache' });
|
|
// => 'hello mustache!'
|
|
|
|
// using backslashes to treat delimiters as plain text
|
|
var compiled = _.template('<%= "\\<%- value %\\>" %>');
|
|
compiled({ 'value': 'ignored' });
|
|
// => '<%- value %>'
|
|
|
|
// using the `imports` option to import `jQuery` as `jq`
|
|
var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
|
|
var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
|
|
compiled({ 'users': ['fred', 'barney'] });
|
|
// => '<li>fred</li><li>barney</li>'
|
|
|
|
// using the `sourceURL` option to specify a custom sourceURL for the template
|
|
var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
|
|
compiled(data);
|
|
// => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
|
|
|
|
// using the `variable` option to ensure a with-statement isn't used in the compiled template
|
|
var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
|
|
compiled.source;
|
|
// => function(data) {
|
|
// var __t, __p = '';
|
|
// __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
|
|
// return __p;
|
|
// }
|
|
|
|
// using the `source` property to inline compiled templates for meaningful
|
|
// line numbers in error messages and a stack trace
|
|
fs.writeFileSync(path.join(cwd, 'jst.js'), '\
|
|
var JST = {\
|
|
"main": ' + _.template(mainText).source + '\
|
|
};\
|
|
');
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_trimstring-charswhitespace"></a>`_.trim([string=''], [chars=whitespace])`
|
|
<a href="#_trimstring-charswhitespace">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11036 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.trim "See the npm package")
|
|
|
|
Removes leading and trailing whitespace or specified characters from `string`.
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to trim.
|
|
2. `[chars=whitespace]` *(string)*: The characters to trim.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the trimmed string.
|
|
|
|
#### Example
|
|
```js
|
|
_.trim(' abc ');
|
|
// => 'abc'
|
|
|
|
_.trim('-_-abc-_-', '_-');
|
|
// => 'abc'
|
|
|
|
_.map([' foo ', ' bar '], _.trim);
|
|
// => ['foo', 'bar']
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_trimleftstring-charswhitespace"></a>`_.trimLeft([string=''], [chars=whitespace])`
|
|
<a href="#_trimleftstring-charswhitespace">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11067 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.trimleft "See the npm package")
|
|
|
|
Removes leading whitespace or specified characters from `string`.
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to trim.
|
|
2. `[chars=whitespace]` *(string)*: The characters to trim.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the trimmed string.
|
|
|
|
#### Example
|
|
```js
|
|
_.trimLeft(' abc ');
|
|
// => 'abc '
|
|
|
|
_.trimLeft('-_-abc-_-', '_-');
|
|
// => 'abc-_-'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_trimrightstring-charswhitespace"></a>`_.trimRight([string=''], [chars=whitespace])`
|
|
<a href="#_trimrightstring-charswhitespace">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11097 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.trimright "See the npm package")
|
|
|
|
Removes trailing whitespace or specified characters from `string`.
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to trim.
|
|
2. `[chars=whitespace]` *(string)*: The characters to trim.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the trimmed string.
|
|
|
|
#### Example
|
|
```js
|
|
_.trimRight(' abc ');
|
|
// => ' abc'
|
|
|
|
_.trimRight('-_-abc-_-', '_-');
|
|
// => '-_-abc'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_truncstring-options-optionslength30-optionsomission-optionsseparator"></a>`_.trunc([string=''], [options], [options.length=30], [options.omission='...'], [options.separator])`
|
|
<a href="#_truncstring-options-optionslength30-optionsomission-optionsseparator">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11149 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.trunc "See the npm package")
|
|
|
|
Truncates `string` if it's longer than the given maximum string length.
|
|
The last characters of the truncated string are replaced with the omission
|
|
string which defaults to "...".
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to truncate.
|
|
2. `[options]` *(Object|number)*: The options object or maximum string length.
|
|
3. `[options.length=30]` *(number)*: The maximum string length.
|
|
4. `[options.omission='...']` *(string)*: The string to indicate text is omitted.
|
|
5. `[options.separator]` *(RegExp|string)*: The separator pattern to truncate to.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the truncated string.
|
|
|
|
#### Example
|
|
```js
|
|
_.trunc('hi-diddly-ho there, neighborino');
|
|
// => 'hi-diddly-ho there, neighbo...'
|
|
|
|
_.trunc('hi-diddly-ho there, neighborino', 24);
|
|
// => 'hi-diddly-ho there, n...'
|
|
|
|
_.trunc('hi-diddly-ho there, neighborino', {
|
|
'length': 24,
|
|
'separator': ' '
|
|
});
|
|
// => 'hi-diddly-ho there,...'
|
|
|
|
_.trunc('hi-diddly-ho there, neighborino', {
|
|
'length': 24,
|
|
'separator': /,? +/
|
|
});
|
|
// => 'hi-diddly-ho there...'
|
|
|
|
_.trunc('hi-diddly-ho there, neighborino', {
|
|
'omission': ' [...]'
|
|
});
|
|
// => 'hi-diddly-ho there, neig [...]'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_unescapestring"></a>`_.unescape([string=''])`
|
|
<a href="#_unescapestring">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11219 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.unescape "See the npm package")
|
|
|
|
The inverse of `_.escape`; this method converts the HTML entities
|
|
`&`, `<`, `>`, `"`, `'`, and ``` in `string` to their
|
|
corresponding characters.
|
|
<br>
|
|
<br>
|
|
**Note:** No other HTML entities are unescaped. To unescape additional HTML
|
|
entities use a third-party library like [_he_](https://mths.be/he).
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to unescape.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the unescaped string.
|
|
|
|
#### Example
|
|
```js
|
|
_.unescape('fred, barney, & pebbles');
|
|
// => 'fred, barney, & pebbles'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_wordsstring-pattern"></a>`_.words([string=''], [pattern])`
|
|
<a href="#_wordsstring-pattern">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11244 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.words "See the npm package")
|
|
|
|
Splits `string` into an array of its words.
|
|
|
|
#### Arguments
|
|
1. `[string='']` *(string)*: The string to inspect.
|
|
2. `[pattern]` *(RegExp|string)*: The pattern to match words.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the words of `string`.
|
|
|
|
#### Example
|
|
```js
|
|
_.words('fred, barney, & pebbles');
|
|
// => ['fred', 'barney', 'pebbles']
|
|
|
|
_.words('fred, barney, & pebbles', /[^, ]+/g);
|
|
// => ['fred', 'barney', '&', 'pebbles']
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `“Utility” Methods`
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_attemptfunc"></a>`_.attempt(func)`
|
|
<a href="#_attemptfunc">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11274 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.attempt "See the npm package")
|
|
|
|
Attempts to invoke `func`, returning either the result or the caught error
|
|
object. Any additional arguments are provided to `func` when it's invoked.
|
|
|
|
#### Arguments
|
|
1. `func` *(Function)*: The function to attempt.
|
|
|
|
#### Returns
|
|
*(*)*: Returns the `func` result or error object.
|
|
|
|
#### Example
|
|
```js
|
|
// avoid throwing errors for invalid selectors
|
|
var elements = _.attempt(function(selector) {
|
|
return document.querySelectorAll(selector);
|
|
}, '>_>');
|
|
|
|
if (_.isError(elements)) {
|
|
elements = [];
|
|
}
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_callbackfunc_identity-thisarg"></a>`_.callback([func=_.identity], [thisArg])`
|
|
<a href="#_callbackfunc_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11320 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.callback "See the npm package")
|
|
|
|
Creates a function that invokes `func` with the `this` binding of `thisArg`
|
|
and arguments of the created function. If `func` is a property name the
|
|
created callback returns the property value for a given element. If `func`
|
|
is an object the created callback returns `true` for elements that contain
|
|
the equivalent object properties, otherwise it returns `false`.
|
|
|
|
#### Aliases
|
|
*_.iteratee*
|
|
|
|
#### Arguments
|
|
1. `[func=_.identity]` *(*)*: The value to convert to a callback.
|
|
2. `[thisArg]` *(*)*: The `this` binding of `func`.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the callback.
|
|
|
|
#### Example
|
|
```js
|
|
var users = [
|
|
{ 'user': 'barney', 'age': 36 },
|
|
{ 'user': 'fred', 'age': 40 }
|
|
];
|
|
|
|
// wrap to create custom callback shorthands
|
|
_.callback = _.wrap(_.callback, function(callback, func, thisArg) {
|
|
var match = /^(.+?)__([gl]t)(.+)$/.exec(func);
|
|
if (!match) {
|
|
return callback(func, thisArg);
|
|
}
|
|
return function(object) {
|
|
return match[2] == 'gt'
|
|
? object[match[1]] > match[3]
|
|
: object[match[1]] < match[3];
|
|
};
|
|
});
|
|
|
|
_.filter(users, 'age__gt36');
|
|
// => [{ 'user': 'fred', 'age': 40 }]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_constantvalue"></a>`_.constant(value)`
|
|
<a href="#_constantvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11345 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.constant "See the npm package")
|
|
|
|
Creates a function that returns `value`.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: The value to return from the new function.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new function.
|
|
|
|
#### Example
|
|
```js
|
|
var object = { 'user': 'fred' };
|
|
var getter = _.constant(object);
|
|
|
|
getter() === object;
|
|
// => true
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_identityvalue"></a>`_.identity(value)`
|
|
<a href="#_identityvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11366 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.identity "See the npm package")
|
|
|
|
This method returns the first argument provided to it.
|
|
|
|
#### Arguments
|
|
1. `value` *(*)*: Any value.
|
|
|
|
#### Returns
|
|
*(*)*: Returns `value`.
|
|
|
|
#### Example
|
|
```js
|
|
var object = { 'user': 'fred' };
|
|
|
|
_.identity(object) === object;
|
|
// => true
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_matchessource"></a>`_.matches(source)`
|
|
<a href="#_matchessource">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11395 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.matches "See the npm package")
|
|
|
|
Creates a function that performs a deep comparison between a given object
|
|
and `source`, returning `true` if the given object has equivalent property
|
|
values, else `false`.
|
|
<br>
|
|
<br>
|
|
**Note:** This method supports comparing arrays, booleans, `Date` objects,
|
|
numbers, `Object` objects, regexes, and strings. Objects are compared by
|
|
their own, not inherited, enumerable properties. For comparing a single
|
|
own or inherited property value see `_.matchesProperty`.
|
|
|
|
#### Arguments
|
|
1. `source` *(Object)*: The object of property values to match.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new function.
|
|
|
|
#### Example
|
|
```js
|
|
var users = [
|
|
{ 'user': 'barney', 'age': 36, 'active': true },
|
|
{ 'user': 'fred', 'age': 40, 'active': false }
|
|
];
|
|
|
|
_.filter(users, _.matches({ 'age': 40, 'active': false }));
|
|
// => [{ 'user': 'fred', 'age': 40, 'active': false }]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_matchespropertypath-srcvalue"></a>`_.matchesProperty(path, srcValue)`
|
|
<a href="#_matchespropertypath-srcvalue">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11423 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.matchesproperty "See the npm package")
|
|
|
|
Creates a function that compares the property value of `path` on a given
|
|
object to `value`.
|
|
<br>
|
|
<br>
|
|
**Note:** This method supports comparing arrays, booleans, `Date` objects,
|
|
numbers, `Object` objects, regexes, and strings. Objects are compared by
|
|
their own, not inherited, enumerable properties.
|
|
|
|
#### Arguments
|
|
1. `path` *(Array|string)*: The path of the property to get.
|
|
2. `srcValue` *(*)*: The value to match.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new function.
|
|
|
|
#### Example
|
|
```js
|
|
var users = [
|
|
{ 'user': 'barney' },
|
|
{ 'user': 'fred' }
|
|
];
|
|
|
|
_.find(users, _.matchesProperty('user', 'fred'));
|
|
// => { 'user': 'fred' }
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_methodpath-args"></a>`_.method(path, [args])`
|
|
<a href="#_methodpath-args">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11450 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.method "See the npm package")
|
|
|
|
Creates a function that invokes the method at `path` on a given object.
|
|
Any additional arguments are provided to the invoked method.
|
|
|
|
#### Arguments
|
|
1. `path` *(Array|string)*: The path of the method to invoke.
|
|
2. `[args]` *(...*)*: The arguments to invoke the method with.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new function.
|
|
|
|
#### Example
|
|
```js
|
|
var objects = [
|
|
{ 'a': { 'b': { 'c': _.constant(2) } } },
|
|
{ 'a': { 'b': { 'c': _.constant(1) } } }
|
|
];
|
|
|
|
_.map(objects, _.method('a.b.c'));
|
|
// => [2, 1]
|
|
|
|
_.invoke(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c');
|
|
// => [1, 2]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_methodofobject-args"></a>`_.methodOf(object, [args])`
|
|
<a href="#_methodofobject-args">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11478 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.methodof "See the npm package")
|
|
|
|
The opposite of `_.method`; this method creates a function that invokes
|
|
the method at a given path on `object`. Any additional arguments are
|
|
provided to the invoked method.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to query.
|
|
2. `[args]` *(...*)*: The arguments to invoke the method with.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new function.
|
|
|
|
#### Example
|
|
```js
|
|
var array = _.times(3, _.constant),
|
|
object = { 'a': array, 'b': array, 'c': array };
|
|
|
|
_.map(['a[2]', 'c[0]'], _.methodOf(object));
|
|
// => [2, 0]
|
|
|
|
_.map([['a', '2'], ['c', '0']], _.methodOf(object));
|
|
// => [2, 0]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_mixinobjectlodash-source-options"></a>`_.mixin([object=lodash], source, [options])`
|
|
<a href="#_mixinobjectlodash-source-options">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11520 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.mixin "See the npm package")
|
|
|
|
Adds all own enumerable function properties of a source object to the
|
|
destination object. If `object` is a function then methods are added to
|
|
its prototype as well.
|
|
<br>
|
|
<br>
|
|
**Note:** Use `_.runInContext` to create a pristine `lodash` function to
|
|
avoid conflicts caused by modifying the original.
|
|
|
|
#### Arguments
|
|
1. `[object=lodash]` *(Function|Object)*: The destination object.
|
|
2. `source` *(Object)*: The object of functions to add.
|
|
3. `[options]` *(Object)*: The options object.
|
|
4. `[options.chain=true]` *(boolean)*: Specify whether the functions added are chainable.
|
|
|
|
#### Returns
|
|
*(Function|Object)*: Returns `object`.
|
|
|
|
#### Example
|
|
```js
|
|
function vowels(string) {
|
|
return _.filter(string, function(v) {
|
|
return /[aeiou]/i.test(v);
|
|
});
|
|
}
|
|
|
|
_.mixin({ 'vowels': vowels });
|
|
_.vowels('fred');
|
|
// => ['e']
|
|
|
|
_('fred').vowels().value();
|
|
// => ['e']
|
|
|
|
_.mixin({ 'vowels': vowels }, { 'chain': false });
|
|
_('fred').vowels();
|
|
// => ['e']
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_noconflict"></a>`_.noConflict()`
|
|
<a href="#_noconflict">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11583 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.noconflict "See the npm package")
|
|
|
|
Reverts the `_` variable to its previous value and returns a reference to
|
|
the `lodash` function.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the `lodash` function.
|
|
|
|
#### Example
|
|
```js
|
|
var lodash = _.noConflict();
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_noop"></a>`_.noop()`
|
|
<a href="#_noop">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11602 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.noop "See the npm package")
|
|
|
|
A no-operation function that returns `undefined` regardless of the
|
|
arguments it receives.
|
|
|
|
#### Example
|
|
```js
|
|
var object = { 'user': 'fred' };
|
|
|
|
_.noop(object) === undefined;
|
|
// => true
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_propertypath"></a>`_.property(path)`
|
|
<a href="#_propertypath">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11628 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.property "See the npm package")
|
|
|
|
Creates a function that returns the property value at `path` on a
|
|
given object.
|
|
|
|
#### Arguments
|
|
1. `path` *(Array|string)*: The path of the property to get.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new function.
|
|
|
|
#### Example
|
|
```js
|
|
var objects = [
|
|
{ 'a': { 'b': { 'c': 2 } } },
|
|
{ 'a': { 'b': { 'c': 1 } } }
|
|
];
|
|
|
|
_.map(objects, _.property('a.b.c'));
|
|
// => [2, 1]
|
|
|
|
_.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
|
|
// => [1, 2]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_propertyofobject"></a>`_.propertyOf(object)`
|
|
<a href="#_propertyofobject">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11652 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.propertyof "See the npm package")
|
|
|
|
The opposite of `_.property`; this method creates a function that returns
|
|
the property value at a given path on `object`.
|
|
|
|
#### Arguments
|
|
1. `object` *(Object)*: The object to query.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns the new function.
|
|
|
|
#### Example
|
|
```js
|
|
var array = [0, 1, 2],
|
|
object = { 'a': array, 'b': array, 'c': array };
|
|
|
|
_.map(['a[2]', 'c[0]'], _.propertyOf(object));
|
|
// => [2, 0]
|
|
|
|
_.map([['a', '2'], ['c', '0']], _.propertyOf(object));
|
|
// => [2, 0]
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_rangestart0-end-step1"></a>`_.range([start=0], end, [step=1])`
|
|
<a href="#_rangestart0-end-step1">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11691 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.range "See the npm package")
|
|
|
|
Creates an array of numbers (positive and/or negative) progressing from
|
|
`start` up to, but not including, `end`. If `end` is not specified it's
|
|
set to `start` with `start` then set to `0`. If `end` is less than `start`
|
|
a zero-length range is created unless a negative `step` is specified.
|
|
|
|
#### Arguments
|
|
1. `[start=0]` *(number)*: The start of the range.
|
|
2. `end` *(number)*: The end of the range.
|
|
3. `[step=1]` *(number)*: The value to increment or decrement by.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the new array of numbers.
|
|
|
|
#### Example
|
|
```js
|
|
_.range(4);
|
|
// => [0, 1, 2, 3]
|
|
|
|
_.range(1, 5);
|
|
// => [1, 2, 3, 4]
|
|
|
|
_.range(0, 20, 5);
|
|
// => [0, 5, 10, 15]
|
|
|
|
_.range(0, -4, -1);
|
|
// => [0, -1, -2, -3]
|
|
|
|
_.range(1, 4, 0);
|
|
// => [1, 1, 1]
|
|
|
|
_.range(0);
|
|
// => []
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_runincontextcontextroot"></a>`_.runInContext([context=root])`
|
|
<a href="#_runincontextcontextroot">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L723 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.runincontext "See the npm package")
|
|
|
|
Create a new pristine `lodash` function using the given `context` object.
|
|
|
|
#### Arguments
|
|
1. `[context=root]` *(Object)*: The context object.
|
|
|
|
#### Returns
|
|
*(Function)*: Returns a new `lodash` function.
|
|
|
|
#### Example
|
|
```js
|
|
_.mixin({ 'foo': _.constant('foo') });
|
|
|
|
var lodash = _.runInContext();
|
|
lodash.mixin({ 'bar': lodash.constant('bar') });
|
|
|
|
_.isFunction(_.foo);
|
|
// => true
|
|
_.isFunction(_.bar);
|
|
// => false
|
|
|
|
lodash.isFunction(lodash.foo);
|
|
// => false
|
|
lodash.isFunction(lodash.bar);
|
|
// => true
|
|
|
|
// using `context` to mock `Date#getTime` use in `_.now`
|
|
var mock = _.runInContext({
|
|
'Date': function() {
|
|
return { 'getTime': getTimeMock };
|
|
}
|
|
});
|
|
|
|
// or creating a suped-up `defer` in Node.js
|
|
var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_timesn-iteratee_identity-thisarg"></a>`_.times(n, [iteratee=_.identity], [thisArg])`
|
|
<a href="#_timesn-iteratee_identity-thisarg">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11744 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.times "See the npm package")
|
|
|
|
Invokes the iteratee function `n` times, returning an array of the results
|
|
of each invocation. The `iteratee` is bound to `thisArg` and invoked with
|
|
one argument; (index).
|
|
|
|
#### Arguments
|
|
1. `n` *(number)*: The number of times to invoke `iteratee`.
|
|
2. `[iteratee=_.identity]` *(Function)*: The function invoked per iteration.
|
|
3. `[thisArg]` *(*)*: The `this` binding of `iteratee`.
|
|
|
|
#### Returns
|
|
*(Array)*: Returns the array of results.
|
|
|
|
#### Example
|
|
```js
|
|
var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
|
|
// => [3, 6, 4]
|
|
|
|
_.times(3, function(n) {
|
|
mage.castSpell(n);
|
|
});
|
|
// => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2`
|
|
|
|
_.times(3, function(n) {
|
|
this.cast(n);
|
|
}, mage);
|
|
// => also invokes `mage.castSpell(n)` three times
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_uniqueidprefix"></a>`_.uniqueId([prefix])`
|
|
<a href="#_uniqueidprefix">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L11782 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.uniqueid "See the npm package")
|
|
|
|
Generates a unique ID. If `prefix` is provided the ID is appended to it.
|
|
|
|
#### Arguments
|
|
1. `[prefix]` *(string)*: The value to prefix the ID with.
|
|
|
|
#### Returns
|
|
*(string)*: Returns the unique ID.
|
|
|
|
#### Example
|
|
```js
|
|
_.uniqueId('contact_');
|
|
// => 'contact_104'
|
|
|
|
_.uniqueId();
|
|
// => '105'
|
|
```
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `Methods`
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_templatesettingsimports_"></a>`_.templateSettings.imports._`
|
|
<a href="#_templatesettingsimports_">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L1122 "View in source") [Ⓣ][1]
|
|
|
|
A reference to the `lodash` function.
|
|
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
## `Properties`
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_version"></a>`_.VERSION`
|
|
<a href="#_version">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L12300 "View in source") [Ⓣ][1]
|
|
|
|
(string): The semantic version number.
|
|
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_support"></a>`_.support`
|
|
<a href="#_support">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L986 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.support "See the npm package")
|
|
|
|
(Object): An object environment feature flags.
|
|
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_supportenumerrorprops"></a>`_.support.enumErrorProps`
|
|
<a href="#_supportenumerrorprops">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L1003 "View in source") [Ⓣ][1]
|
|
|
|
(boolean): Detect if `name` or `message` properties of `Error.prototype` are
|
|
enumerable by default (IE < 9, Safari < 5.1).
|
|
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_supportenumprototypes"></a>`_.support.enumPrototypes`
|
|
<a href="#_supportenumprototypes">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L1017 "View in source") [Ⓣ][1]
|
|
|
|
(boolean): Detect if `prototype` properties are enumerable by default.
|
|
<br>
|
|
<br>
|
|
Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
|
|
(if the prototype or a property on the prototype has been set)
|
|
incorrectly set the `[[Enumerable]]` value of a function's `prototype`
|
|
property to `true`.
|
|
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_supportnonenumshadows"></a>`_.support.nonEnumShadows`
|
|
<a href="#_supportnonenumshadows">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L1028 "View in source") [Ⓣ][1]
|
|
|
|
(boolean): Detect if properties shadowing those on `Object.prototype` are non-enumerable.
|
|
<br>
|
|
<br>
|
|
In IE < 9 an object's own properties, shadowing non-enumerable ones,
|
|
are made non-enumerable as well (a.k.a the JScript `[[DontEnum]]` bug).
|
|
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_supportownlast"></a>`_.support.ownLast`
|
|
<a href="#_supportownlast">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L1036 "View in source") [Ⓣ][1]
|
|
|
|
(boolean): Detect if own properties are iterated after inherited properties (IE < 9).
|
|
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_supportspliceobjects"></a>`_.support.spliceObjects`
|
|
<a href="#_supportspliceobjects">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L1051 "View in source") [Ⓣ][1]
|
|
|
|
(boolean): Detect if `Array#shift` and `Array#splice` augment array-like objects
|
|
correctly.
|
|
<br>
|
|
<br>
|
|
Firefox < 10, compatibility modes of IE 8, and IE < 9 have buggy Array
|
|
`shift()` and `splice()` functions that fail to remove the last element,
|
|
`value[0]`, of array-like objects even though the "length" property is
|
|
set to `0`. The `shift()` method is buggy in compatibility modes of IE 8,
|
|
while `splice()` is buggy regardless of mode in IE < 9.
|
|
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_supportunindexedchars"></a>`_.support.unindexedChars`
|
|
<a href="#_supportunindexedchars">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L1062 "View in source") [Ⓣ][1]
|
|
|
|
(boolean): Detect lack of support for accessing string characters by index.
|
|
<br>
|
|
<br>
|
|
IE < 8 can't access characters by index. IE 8 can only access characters
|
|
by index on string literals, not string objects.
|
|
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_templatesettings"></a>`_.templateSettings`
|
|
<a href="#_templatesettings">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L1074 "View in source") [Ⓣ][1] [Ⓝ](https://www.npmjs.com/package/lodash.templatesettings "See the npm package")
|
|
|
|
(Object): By default, the template delimiters used by lodash are like those in
|
|
embedded Ruby (ERB). Change the following template settings to use
|
|
alternative delimiters.
|
|
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_templatesettingsescape"></a>`_.templateSettings.escape`
|
|
<a href="#_templatesettingsescape">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L1082 "View in source") [Ⓣ][1]
|
|
|
|
(RegExp): Used to detect `data` property values to be HTML-escaped.
|
|
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_templatesettingsevaluate"></a>`_.templateSettings.evaluate`
|
|
<a href="#_templatesettingsevaluate">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L1090 "View in source") [Ⓣ][1]
|
|
|
|
(RegExp): Used to detect code to be evaluated.
|
|
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_templatesettingsimports"></a>`_.templateSettings.imports`
|
|
<a href="#_templatesettingsimports">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L1114 "View in source") [Ⓣ][1]
|
|
|
|
(Object): Used to import variables into the compiled template.
|
|
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_templatesettingsinterpolate"></a>`_.templateSettings.interpolate`
|
|
<a href="#_templatesettingsinterpolate">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L1098 "View in source") [Ⓣ][1]
|
|
|
|
(RegExp): Used to detect `data` property values to inject.
|
|
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- div -->
|
|
|
|
### <a id="_templatesettingsvariable"></a>`_.templateSettings.variable`
|
|
<a href="#_templatesettingsvariable">#</a> [Ⓢ](https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js#L1106 "View in source") [Ⓣ][1]
|
|
|
|
(string): Used to reference the data object in the template text.
|
|
|
|
* * *
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- /div -->
|
|
|
|
<!-- /div -->
|
|
|
|
[1]: #array "Jump back to the TOC."
|