PageRenderTime 45ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/slider/node_modules/grunt/node_modules/findup-sync/node_modules/lodash/doc/README.md

https://bitbucket.org/kristijanhusak/koaslider
Markdown | 3590 lines | 2375 code | 1215 blank | 0 comment | 0 complexity | a71626c79bf93a5ff610106e395bc913 MD5 | raw file
Possible License(s): BSD-3-Clause, MIT

Large files files are truncated, but you can click here to view the full file

  1. # Lo-Dash <sup>v1.0.1</sup>
  2. <!-- div -->
  3. <!-- div -->
  4. ## <a id="Arrays"></a>`Arrays`
  5. * [`_.compact`](#_compactarray)
  6. * [`_.difference`](#_differencearray--array1-array2-)
  7. * [`_.drop`](#_restarray--callbackn1-thisarg)
  8. * [`_.first`](#_firstarray--callbackn-thisarg)
  9. * [`_.flatten`](#_flattenarray-shallow)
  10. * [`_.head`](#_firstarray--callbackn-thisarg)
  11. * [`_.indexOf`](#_indexofarray-value--fromindex0)
  12. * [`_.initial`](#_initialarray--callbackn1-thisarg)
  13. * [`_.intersection`](#_intersectionarray1-array2-)
  14. * [`_.last`](#_lastarray--callbackn-thisarg)
  15. * [`_.lastIndexOf`](#_lastindexofarray-value--fromindexarraylength-1)
  16. * [`_.object`](#_objectkeys--values)
  17. * [`_.range`](#_rangestart0-end--step1)
  18. * [`_.rest`](#_restarray--callbackn1-thisarg)
  19. * [`_.sortedIndex`](#_sortedindexarray-value--callbackidentity-thisarg)
  20. * [`_.tail`](#_restarray--callbackn1-thisarg)
  21. * [`_.take`](#_firstarray--callbackn-thisarg)
  22. * [`_.union`](#_unionarray1-array2-)
  23. * [`_.uniq`](#_uniqarray--issortedfalse-callbackidentity-thisarg)
  24. * [`_.unique`](#_uniqarray--issortedfalse-callbackidentity-thisarg)
  25. * [`_.without`](#_withoutarray--value1-value2-)
  26. * [`_.zip`](#_ziparray1-array2-)
  27. <!-- /div -->
  28. <!-- div -->
  29. ## `Chaining`
  30. * [`_`](#_value)
  31. * [`_.tap`](#_tapvalue-interceptor)
  32. * [`_.prototype.toString`](#_prototypetostring)
  33. * [`_.prototype.value`](#_prototypevalueof)
  34. * [`_.prototype.valueOf`](#_prototypevalueof)
  35. <!-- /div -->
  36. <!-- div -->
  37. ## `Collections`
  38. * [`_.all`](#_everycollection--callbackidentity-thisarg)
  39. * [`_.any`](#_somecollection--callbackidentity-thisarg)
  40. * [`_.at`](#_atcollection--index1-index2-)
  41. * [`_.collect`](#_mapcollection--callbackidentity-thisarg)
  42. * [`_.contains`](#_containscollection-target--fromindex0)
  43. * [`_.countBy`](#_countbycollection--callbackidentity-thisarg)
  44. * [`_.detect`](#_findcollection--callbackidentity-thisarg)
  45. * [`_.each`](#_foreachcollection--callbackidentity-thisarg)
  46. * [`_.every`](#_everycollection--callbackidentity-thisarg)
  47. * [`_.filter`](#_filtercollection--callbackidentity-thisarg)
  48. * [`_.find`](#_findcollection--callbackidentity-thisarg)
  49. * [`_.foldl`](#_reducecollection--callbackidentity-accumulator-thisarg)
  50. * [`_.foldr`](#_reducerightcollection--callbackidentity-accumulator-thisarg)
  51. * [`_.forEach`](#_foreachcollection--callbackidentity-thisarg)
  52. * [`_.groupBy`](#_groupbycollection--callbackidentity-thisarg)
  53. * [`_.include`](#_containscollection-target--fromindex0)
  54. * [`_.inject`](#_reducecollection--callbackidentity-accumulator-thisarg)
  55. * [`_.invoke`](#_invokecollection-methodname--arg1-arg2-)
  56. * [`_.map`](#_mapcollection--callbackidentity-thisarg)
  57. * [`_.max`](#_maxcollection--callbackidentity-thisarg)
  58. * [`_.min`](#_mincollection--callbackidentity-thisarg)
  59. * [`_.pluck`](#_pluckcollection-property)
  60. * [`_.reduce`](#_reducecollection--callbackidentity-accumulator-thisarg)
  61. * [`_.reduceRight`](#_reducerightcollection--callbackidentity-accumulator-thisarg)
  62. * [`_.reject`](#_rejectcollection--callbackidentity-thisarg)
  63. * [`_.select`](#_filtercollection--callbackidentity-thisarg)
  64. * [`_.shuffle`](#_shufflecollection)
  65. * [`_.size`](#_sizecollection)
  66. * [`_.some`](#_somecollection--callbackidentity-thisarg)
  67. * [`_.sortBy`](#_sortbycollection--callbackidentity-thisarg)
  68. * [`_.toArray`](#_toarraycollection)
  69. * [`_.where`](#_wherecollection-properties)
  70. <!-- /div -->
  71. <!-- div -->
  72. ## `Functions`
  73. * [`_.after`](#_aftern-func)
  74. * [`_.bind`](#_bindfunc--thisarg-arg1-arg2-)
  75. * [`_.bindAll`](#_bindallobject--methodname1-methodname2-)
  76. * [`_.bindKey`](#_bindkeyobject-key--arg1-arg2-)
  77. * [`_.compose`](#_composefunc1-func2-)
  78. * [`_.debounce`](#_debouncefunc-wait-immediate)
  79. * [`_.defer`](#_deferfunc--arg1-arg2-)
  80. * [`_.delay`](#_delayfunc-wait--arg1-arg2-)
  81. * [`_.memoize`](#_memoizefunc--resolver)
  82. * [`_.once`](#_oncefunc)
  83. * [`_.partial`](#_partialfunc--arg1-arg2-)
  84. * [`_.partialRight`](#_partialrightfunc--arg1-arg2-)
  85. * [`_.throttle`](#_throttlefunc-wait)
  86. * [`_.wrap`](#_wrapvalue-wrapper)
  87. <!-- /div -->
  88. <!-- div -->
  89. ## `Objects`
  90. * [`_.assign`](#_assignobject--source1-source2--callback-thisarg)
  91. * [`_.clone`](#_clonevalue--deepfalse-callback-thisarg)
  92. * [`_.cloneDeep`](#_clonedeepvalue--callback-thisarg)
  93. * [`_.defaults`](#_defaultsobject--source1-source2-)
  94. * [`_.extend`](#_assignobject--source1-source2--callback-thisarg)
  95. * [`_.forIn`](#_forinobject--callbackidentity-thisarg)
  96. * [`_.forOwn`](#_forownobject--callbackidentity-thisarg)
  97. * [`_.functions`](#_functionsobject)
  98. * [`_.has`](#_hasobject-property)
  99. * [`_.invert`](#_invertobject)
  100. * [`_.isArguments`](#_isargumentsvalue)
  101. * [`_.isArray`](#_isarrayvalue)
  102. * [`_.isBoolean`](#_isbooleanvalue)
  103. * [`_.isDate`](#_isdatevalue)
  104. * [`_.isElement`](#_iselementvalue)
  105. * [`_.isEmpty`](#_isemptyvalue)
  106. * [`_.isEqual`](#_isequala-b--callback-thisarg)
  107. * [`_.isFinite`](#_isfinitevalue)
  108. * [`_.isFunction`](#_isfunctionvalue)
  109. * [`_.isNaN`](#_isnanvalue)
  110. * [`_.isNull`](#_isnullvalue)
  111. * [`_.isNumber`](#_isnumbervalue)
  112. * [`_.isObject`](#_isobjectvalue)
  113. * [`_.isPlainObject`](#_isplainobjectvalue)
  114. * [`_.isRegExp`](#_isregexpvalue)
  115. * [`_.isString`](#_isstringvalue)
  116. * [`_.isUndefined`](#_isundefinedvalue)
  117. * [`_.keys`](#_keysobject)
  118. * [`_.merge`](#_mergeobject--source1-source2--callback-thisarg)
  119. * [`_.methods`](#_functionsobject)
  120. * [`_.omit`](#_omitobject-callback-prop1-prop2--thisarg)
  121. * [`_.pairs`](#_pairsobject)
  122. * [`_.pick`](#_pickobject-callback-prop1-prop2--thisarg)
  123. * [`_.values`](#_valuesobject)
  124. <!-- /div -->
  125. <!-- div -->
  126. ## `Utilities`
  127. * [`_.escape`](#_escapestring)
  128. * [`_.identity`](#_identityvalue)
  129. * [`_.mixin`](#_mixinobject)
  130. * [`_.noConflict`](#_noconflict)
  131. * [`_.random`](#_randommin0-max1)
  132. * [`_.result`](#_resultobject-property)
  133. * [`_.template`](#_templatetext-data-options)
  134. * [`_.times`](#_timesn-callback--thisarg)
  135. * [`_.unescape`](#_unescapestring)
  136. * [`_.uniqueId`](#_uniqueidprefix)
  137. <!-- /div -->
  138. <!-- div -->
  139. ## `Methods`
  140. * [`_.templateSettings.imports._`](#_templatesettingsimports_)
  141. <!-- /div -->
  142. <!-- div -->
  143. ## `Properties`
  144. * [`_.VERSION`](#_version)
  145. * [`_.templateSettings`](#_templatesettings)
  146. * [`_.templateSettings.escape`](#_templatesettingsescape)
  147. * [`_.templateSettings.evaluate`](#_templatesettingsevaluate)
  148. * [`_.templateSettings.interpolate`](#_templatesettingsinterpolate)
  149. * [`_.templateSettings.variable`](#_templatesettingsvariable)
  150. * [`_.templateSettings.imports`](#_templatesettingsimports)
  151. <!-- /div -->
  152. <!-- /div -->
  153. <!-- div -->
  154. <!-- div -->
  155. ## `“Arrays” Methods`
  156. <!-- div -->
  157. ### <a id="_compactarray"></a>`_.compact(array)`
  158. <a href="#_compactarray">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3166 "View in source") [&#x24C9;][1]
  159. Creates an array with all falsey values of `array` removed. The values `false`, `null`, `0`, `""`, `undefined` and `NaN` are all falsey.
  160. #### Arguments
  161. 1. `array` *(Array)*: The array to compact.
  162. #### Returns
  163. *(Array)*: Returns a new filtered array.
  164. #### Example
  165. ```js
  166. _.compact([0, 1, false, 2, '', 3]);
  167. // => [1, 2, 3]
  168. ```
  169. * * *
  170. <!-- /div -->
  171. <!-- div -->
  172. ### <a id="_differencearray--array1-array2-"></a>`_.difference(array [, array1, array2, ...])`
  173. <a href="#_differencearray--array1-array2-">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3196 "View in source") [&#x24C9;][1]
  174. Creates an array of `array` elements not present in the other arrays using strict equality for comparisons, i.e. `===`.
  175. #### Arguments
  176. 1. `array` *(Array)*: The array to process.
  177. 2. `[array1, array2, ...]` *(Array)*: Arrays to check.
  178. #### Returns
  179. *(Array)*: Returns a new array of `array` elements not present in the other arrays.
  180. #### Example
  181. ```js
  182. _.difference([1, 2, 3, 4, 5], [5, 2, 10]);
  183. // => [1, 3, 4]
  184. ```
  185. * * *
  186. <!-- /div -->
  187. <!-- div -->
  188. ### <a id="_firstarray--callbackn-thisarg"></a>`_.first(array [, callback|n, thisArg])`
  189. <a href="#_firstarray--callbackn-thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3268 "View in source") [&#x24C9;][1]
  190. Gets the first element of the `array`. If a number `n` is passed, the first `n` elements of the `array` are returned. If a `callback` function is passed, the first elements the `callback` returns truthy for are returned. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*.
  191. If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element.
  192. If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`.
  193. #### Aliases
  194. *head, take*
  195. #### Arguments
  196. 1. `array` *(Array)*: The array to query.
  197. 2. `[callback|n]` *(Function|Object|Number|String)*: The function called per element or the number of elements to return. If a property name or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively.
  198. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`.
  199. #### Returns
  200. *(Mixed)*: Returns the first element(s) of `array`.
  201. #### Example
  202. ```js
  203. _.first([1, 2, 3]);
  204. // => 1
  205. _.first([1, 2, 3], 2);
  206. // => [1, 2]
  207. _.first([1, 2, 3], function(num) {
  208. return num < 3;
  209. });
  210. // => [1, 2]
  211. var food = [
  212. { 'name': 'banana', 'organic': true },
  213. { 'name': 'beet', 'organic': false },
  214. ];
  215. // using "_.pluck" callback shorthand
  216. _.first(food, 'organic');
  217. // => [{ 'name': 'banana', 'organic': true }]
  218. var food = [
  219. { 'name': 'apple', 'type': 'fruit' },
  220. { 'name': 'banana', 'type': 'fruit' },
  221. { 'name': 'beet', 'type': 'vegetable' }
  222. ];
  223. // using "_.where" callback shorthand
  224. _.first(food, { 'type': 'fruit' });
  225. // => [{ 'name': 'apple', 'type': 'fruit' }, { 'name': 'banana', 'type': 'fruit' }]
  226. ```
  227. * * *
  228. <!-- /div -->
  229. <!-- div -->
  230. ### <a id="_flattenarray-shallow"></a>`_.flatten(array, shallow)`
  231. <a href="#_flattenarray-shallow">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3307 "View in source") [&#x24C9;][1]
  232. Flattens a nested array *(the nesting can be to any depth)*. If `shallow` is truthy, `array` will only be flattened a single level.
  233. #### Arguments
  234. 1. `array` *(Array)*: The array to compact.
  235. 2. `shallow` *(Boolean)*: A flag to indicate only flattening a single level.
  236. #### Returns
  237. *(Array)*: Returns a new flattened array.
  238. #### Example
  239. ```js
  240. _.flatten([1, [2], [3, [[4]]]]);
  241. // => [1, 2, 3, 4];
  242. _.flatten([1, [2], [3, [[4]]]], true);
  243. // => [1, 2, 3, [[4]]];
  244. ```
  245. * * *
  246. <!-- /div -->
  247. <!-- div -->
  248. ### <a id="_indexofarray-value--fromindex0"></a>`_.indexOf(array, value [, fromIndex=0])`
  249. <a href="#_indexofarray-value--fromindex0">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3349 "View in source") [&#x24C9;][1]
  250. Gets the index at which the first occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `fromIndex` will run a faster binary search.
  251. #### Arguments
  252. 1. `array` *(Array)*: The array to search.
  253. 2. `value` *(Mixed)*: The value to search for.
  254. 3. `[fromIndex=0]` *(Boolean|Number)*: The index to search from or `true` to perform a binary search on a sorted `array`.
  255. #### Returns
  256. *(Number)*: Returns the index of the matched value or `-1`.
  257. #### Example
  258. ```js
  259. _.indexOf([1, 2, 3, 1, 2, 3], 2);
  260. // => 1
  261. _.indexOf([1, 2, 3, 1, 2, 3], 2, 3);
  262. // => 4
  263. _.indexOf([1, 1, 2, 2, 3, 3], 2, true);
  264. // => 2
  265. ```
  266. * * *
  267. <!-- /div -->
  268. <!-- div -->
  269. ### <a id="_initialarray--callbackn1-thisarg"></a>`_.initial(array [, callback|n=1, thisArg])`
  270. <a href="#_initialarray--callbackn1-thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3423 "View in source") [&#x24C9;][1]
  271. Gets all but the last element of `array`. If a number `n` is passed, the last `n` elements are excluded from the result. If a `callback` function is passed, the last elements the `callback` returns truthy for are excluded from the result. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*.
  272. If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element.
  273. If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`.
  274. #### Arguments
  275. 1. `array` *(Array)*: The array to query.
  276. 2. `[callback|n=1]` *(Function|Object|Number|String)*: The function called per element or the number of elements to exclude. If a property name or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively.
  277. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`.
  278. #### Returns
  279. *(Array)*: Returns a slice of `array`.
  280. #### Example
  281. ```js
  282. _.initial([1, 2, 3]);
  283. // => [1, 2]
  284. _.initial([1, 2, 3], 2);
  285. // => [1]
  286. _.initial([1, 2, 3], function(num) {
  287. return num > 1;
  288. });
  289. // => [1]
  290. var food = [
  291. { 'name': 'beet', 'organic': false },
  292. { 'name': 'carrot', 'organic': true }
  293. ];
  294. // using "_.pluck" callback shorthand
  295. _.initial(food, 'organic');
  296. // => [{ 'name': 'beet', 'organic': false }]
  297. var food = [
  298. { 'name': 'banana', 'type': 'fruit' },
  299. { 'name': 'beet', 'type': 'vegetable' },
  300. { 'name': 'carrot', 'type': 'vegetable' }
  301. ];
  302. // using "_.where" callback shorthand
  303. _.initial(food, { 'type': 'vegetable' });
  304. // => [{ 'name': 'banana', 'type': 'fruit' }]
  305. ```
  306. * * *
  307. <!-- /div -->
  308. <!-- div -->
  309. ### <a id="_intersectionarray1-array2-"></a>`_.intersection([array1, array2, ...])`
  310. <a href="#_intersectionarray1-array2-">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3457 "View in source") [&#x24C9;][1]
  311. Computes the intersection of all the passed-in arrays using strict equality for comparisons, i.e. `===`.
  312. #### Arguments
  313. 1. `[array1, array2, ...]` *(Array)*: Arrays to process.
  314. #### Returns
  315. *(Array)*: Returns a new array of unique elements that are present in **all** of the arrays.
  316. #### Example
  317. ```js
  318. _.intersection([1, 2, 3], [101, 2, 1, 10], [2, 1]);
  319. // => [1, 2]
  320. ```
  321. * * *
  322. <!-- /div -->
  323. <!-- div -->
  324. ### <a id="_lastarray--callbackn-thisarg"></a>`_.last(array [, callback|n, thisArg])`
  325. <a href="#_lastarray--callbackn-thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3548 "View in source") [&#x24C9;][1]
  326. Gets the last element of the `array`. If a number `n` is passed, the last `n` elements of the `array` are returned. If a `callback` function is passed, the last elements the `callback` returns truthy for are returned. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*.
  327. If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element.
  328. If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`.
  329. #### Arguments
  330. 1. `array` *(Array)*: The array to query.
  331. 2. `[callback|n]` *(Function|Object|Number|String)*: The function called per element or the number of elements to return. If a property name or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively.
  332. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`.
  333. #### Returns
  334. *(Mixed)*: Returns the last element(s) of `array`.
  335. #### Example
  336. ```js
  337. _.last([1, 2, 3]);
  338. // => 3
  339. _.last([1, 2, 3], 2);
  340. // => [2, 3]
  341. _.last([1, 2, 3], function(num) {
  342. return num > 1;
  343. });
  344. // => [2, 3]
  345. var food = [
  346. { 'name': 'beet', 'organic': false },
  347. { 'name': 'carrot', 'organic': true }
  348. ];
  349. // using "_.pluck" callback shorthand
  350. _.last(food, 'organic');
  351. // => [{ 'name': 'carrot', 'organic': true }]
  352. var food = [
  353. { 'name': 'banana', 'type': 'fruit' },
  354. { 'name': 'beet', 'type': 'vegetable' },
  355. { 'name': 'carrot', 'type': 'vegetable' }
  356. ];
  357. // using "_.where" callback shorthand
  358. _.last(food, { 'type': 'vegetable' });
  359. // => [{ 'name': 'beet', 'type': 'vegetable' }, { 'name': 'carrot', 'type': 'vegetable' }]
  360. ```
  361. * * *
  362. <!-- /div -->
  363. <!-- div -->
  364. ### <a id="_lastindexofarray-value--fromindexarraylength-1"></a>`_.lastIndexOf(array, value [, fromIndex=array.length-1])`
  365. <a href="#_lastindexofarray-value--fromindexarraylength-1">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3589 "View in source") [&#x24C9;][1]
  366. Gets the index at which the last occurrence of `value` is found using strict equality for comparisons, i.e. `===`. If `fromIndex` is negative, it is used as the offset from the end of the collection.
  367. #### Arguments
  368. 1. `array` *(Array)*: The array to search.
  369. 2. `value` *(Mixed)*: The value to search for.
  370. 3. `[fromIndex=array.length-1]` *(Number)*: The index to search from.
  371. #### Returns
  372. *(Number)*: Returns the index of the matched value or `-1`.
  373. #### Example
  374. ```js
  375. _.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
  376. // => 4
  377. _.lastIndexOf([1, 2, 3, 1, 2, 3], 2, 3);
  378. // => 1
  379. ```
  380. * * *
  381. <!-- /div -->
  382. <!-- div -->
  383. ### <a id="_objectkeys--values"></a>`_.object(keys [, values=[]])`
  384. <a href="#_objectkeys--values">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3619 "View in source") [&#x24C9;][1]
  385. Creates an object composed from arrays of `keys` and `values`. Pass either a single two dimensional array, i.e. `[[key1, value1], [key2, value2]]`, or two arrays, one of `keys` and one of corresponding `values`.
  386. #### Arguments
  387. 1. `keys` *(Array)*: The array of keys.
  388. 2. `[values=[]]` *(Array)*: The array of values.
  389. #### Returns
  390. *(Object)*: Returns an object composed of the given keys and corresponding values.
  391. #### Example
  392. ```js
  393. _.object(['moe', 'larry'], [30, 40]);
  394. // => { 'moe': 30, 'larry': 40 }
  395. ```
  396. * * *
  397. <!-- /div -->
  398. <!-- div -->
  399. ### <a id="_rangestart0-end--step1"></a>`_.range([start=0], end [, step=1])`
  400. <a href="#_rangestart0-end--step1">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3663 "View in source") [&#x24C9;][1]
  401. Creates an array of numbers *(positive and/or negative)* progressing from `start` up to but not including `end`.
  402. #### Arguments
  403. 1. `[start=0]` *(Number)*: The start of the range.
  404. 2. `end` *(Number)*: The end of the range.
  405. 3. `[step=1]` *(Number)*: The value to increment or descrement by.
  406. #### Returns
  407. *(Array)*: Returns a new range array.
  408. #### Example
  409. ```js
  410. _.range(10);
  411. // => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  412. _.range(1, 11);
  413. // => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  414. _.range(0, 30, 5);
  415. // => [0, 5, 10, 15, 20, 25]
  416. _.range(0, -10, -1);
  417. // => [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
  418. _.range(0);
  419. // => []
  420. ```
  421. * * *
  422. <!-- /div -->
  423. <!-- div -->
  424. ### <a id="_restarray--callbackn1-thisarg"></a>`_.rest(array [, callback|n=1, thisArg])`
  425. <a href="#_restarray--callbackn1-thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3741 "View in source") [&#x24C9;][1]
  426. The opposite of `_.initial`, this method gets all but the first value of `array`. If a number `n` is passed, the first `n` values are excluded from the result. If a `callback` function is passed, the first elements the `callback` returns truthy for are excluded from the result. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*.
  427. If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element.
  428. If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`.
  429. #### Aliases
  430. *drop, tail*
  431. #### Arguments
  432. 1. `array` *(Array)*: The array to query.
  433. 2. `[callback|n=1]` *(Function|Object|Number|String)*: The function called per element or the number of elements to exclude. If a property name or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively.
  434. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`.
  435. #### Returns
  436. *(Array)*: Returns a slice of `array`.
  437. #### Example
  438. ```js
  439. _.rest([1, 2, 3]);
  440. // => [2, 3]
  441. _.rest([1, 2, 3], 2);
  442. // => [3]
  443. _.rest([1, 2, 3], function(num) {
  444. return num < 3;
  445. });
  446. // => [3]
  447. var food = [
  448. { 'name': 'banana', 'organic': true },
  449. { 'name': 'beet', 'organic': false },
  450. ];
  451. // using "_.pluck" callback shorthand
  452. _.rest(food, 'organic');
  453. // => [{ 'name': 'beet', 'organic': false }]
  454. var food = [
  455. { 'name': 'apple', 'type': 'fruit' },
  456. { 'name': 'banana', 'type': 'fruit' },
  457. { 'name': 'beet', 'type': 'vegetable' }
  458. ];
  459. // using "_.where" callback shorthand
  460. _.rest(food, { 'type': 'fruit' });
  461. // => [{ 'name': 'beet', 'type': 'vegetable' }]
  462. ```
  463. * * *
  464. <!-- /div -->
  465. <!-- div -->
  466. ### <a id="_sortedindexarray-value--callbackidentity-thisarg"></a>`_.sortedIndex(array, value [, callback=identity, thisArg])`
  467. <a href="#_sortedindexarray-value--callbackidentity-thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3805 "View in source") [&#x24C9;][1]
  468. Uses a binary search to determine the smallest index at which the `value` should be inserted into `array` in order to maintain the sort order of the sorted `array`. If `callback` is passed, it will be executed for `value` and each element in `array` to compute their sort ranking. The `callback` is bound to `thisArg` and invoked with one argument; *(value)*.
  469. If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element.
  470. If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`.
  471. #### Arguments
  472. 1. `array` *(Array)*: The array to iterate over.
  473. 2. `value` *(Mixed)*: The value to evaluate.
  474. 3. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a property name or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively.
  475. 4. `[thisArg]` *(Mixed)*: The `this` binding of `callback`.
  476. #### Returns
  477. *(Number)*: Returns the index at which the value should be inserted into `array`.
  478. #### Example
  479. ```js
  480. _.sortedIndex([20, 30, 50], 40);
  481. // => 2
  482. // using "_.pluck" callback shorthand
  483. _.sortedIndex([{ 'x': 20 }, { 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
  484. // => 2
  485. var dict = {
  486. 'wordToNumber': { 'twenty': 20, 'thirty': 30, 'fourty': 40, 'fifty': 50 }
  487. };
  488. _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) {
  489. return dict.wordToNumber[word];
  490. });
  491. // => 2
  492. _.sortedIndex(['twenty', 'thirty', 'fifty'], 'fourty', function(word) {
  493. return this.wordToNumber[word];
  494. }, dict);
  495. // => 2
  496. ```
  497. * * *
  498. <!-- /div -->
  499. <!-- div -->
  500. ### <a id="_unionarray1-array2-"></a>`_.union([array1, array2, ...])`
  501. <a href="#_unionarray1-array2-">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3837 "View in source") [&#x24C9;][1]
  502. Computes the union of the passed-in arrays using strict equality for comparisons, i.e. `===`.
  503. #### Arguments
  504. 1. `[array1, array2, ...]` *(Array)*: Arrays to process.
  505. #### Returns
  506. *(Array)*: Returns a new array of unique values, in order, that are present in one or more of the arrays.
  507. #### Example
  508. ```js
  509. _.union([1, 2, 3], [101, 2, 1, 10], [2, 1]);
  510. // => [1, 2, 3, 101, 10]
  511. ```
  512. * * *
  513. <!-- /div -->
  514. <!-- div -->
  515. ### <a id="_uniqarray--issortedfalse-callbackidentity-thisarg"></a>`_.uniq(array [, isSorted=false, callback=identity, thisArg])`
  516. <a href="#_uniqarray--issortedfalse-callbackidentity-thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3884 "View in source") [&#x24C9;][1]
  517. Creates a duplicate-value-free version of the `array` using strict equality for comparisons, i.e. `===`. If the `array` is already sorted, passing `true` for `isSorted` will run a faster algorithm. If `callback` is passed, each element of `array` is passed through a callback` before uniqueness is computed. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, array)*.
  518. If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element.
  519. If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`.
  520. #### Aliases
  521. *unique*
  522. #### Arguments
  523. 1. `array` *(Array)*: The array to process.
  524. 2. `[isSorted=false]` *(Boolean)*: A flag to indicate that the `array` is already sorted.
  525. 3. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a property name or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively.
  526. 4. `[thisArg]` *(Mixed)*: The `this` binding of `callback`.
  527. #### Returns
  528. *(Array)*: Returns a duplicate-value-free array.
  529. #### Example
  530. ```js
  531. _.uniq([1, 2, 1, 3, 1]);
  532. // => [1, 2, 3]
  533. _.uniq([1, 1, 2, 2, 3], true);
  534. // => [1, 2, 3]
  535. _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return Math.floor(num); });
  536. // => [1, 2, 3]
  537. _.uniq([1, 2, 1.5, 3, 2.5], function(num) { return this.floor(num); }, Math);
  538. // => [1, 2, 3]
  539. // using "_.pluck" callback shorthand
  540. _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  541. // => [{ 'x': 1 }, { 'x': 2 }]
  542. ```
  543. * * *
  544. <!-- /div -->
  545. <!-- div -->
  546. ### <a id="_withoutarray--value1-value2-"></a>`_.without(array [, value1, value2, ...])`
  547. <a href="#_withoutarray--value1-value2-">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3943 "View in source") [&#x24C9;][1]
  548. Creates an array with all occurrences of the passed values removed using strict equality for comparisons, i.e. `===`.
  549. #### Arguments
  550. 1. `array` *(Array)*: The array to filter.
  551. 2. `[value1, value2, ...]` *(Mixed)*: Values to remove.
  552. #### Returns
  553. *(Array)*: Returns a new filtered array.
  554. #### Example
  555. ```js
  556. _.without([1, 2, 1, 0, 3, 1, 4], 0, 1);
  557. // => [2, 3, 4]
  558. ```
  559. * * *
  560. <!-- /div -->
  561. <!-- div -->
  562. ### <a id="_ziparray1-array2-"></a>`_.zip([array1, array2, ...])`
  563. <a href="#_ziparray1-array2-">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L3974 "View in source") [&#x24C9;][1]
  564. Groups the elements of each array at their corresponding indexes. Useful for separate data sources that are coordinated through matching array indexes. For a matrix of nested arrays, `_.zip.apply(...)` can transpose the matrix in a similar fashion.
  565. #### Arguments
  566. 1. `[array1, array2, ...]` *(Array)*: Arrays to process.
  567. #### Returns
  568. *(Array)*: Returns a new array of grouped elements.
  569. #### Example
  570. ```js
  571. _.zip(['moe', 'larry'], [30, 40], [true, false]);
  572. // => [['moe', 30, true], ['larry', 40, false]]
  573. ```
  574. * * *
  575. <!-- /div -->
  576. <!-- /div -->
  577. <!-- div -->
  578. ## `Chaining Methods`
  579. <!-- div -->
  580. ### <a id="_value"></a>`_(value)`
  581. <a href="#_value">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L272 "View in source") [&#x24C9;][1]
  582. Creates a `lodash` object, that wraps the given `value`, to enable method chaining.
  583. In addition to Lo-Dash methods, wrappers also have the following `Array` methods:<br>
  584. `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`, `splice`, and `unshift`
  585. The chainable wrapper functions are:<br>
  586. `after`, `assign`, `bind`, `bindAll`, `bindKey`, `chain`, `compact`, `compose`, `concat`, `countBy`, `debounce`, `defaults`, `defer`, `delay`, `difference`, `filter`, `flatten`, `forEach`, `forIn`, `forOwn`, `functions`, `groupBy`, `initial`, `intersection`, `invert`, `invoke`, `keys`, `map`, `max`, `memoize`, `merge`, `min`, `object`, `omit`, `once`, `pairs`, `partial`, `partialRight`, `pick`, `pluck`, `push`, `range`, `reject`, `rest`, `reverse`, `shuffle`, `slice`, `sort`, `sortBy`, `splice`, `tap`, `throttle`, `times`, `toArray`, `union`, `uniq`, `unshift`, `values`, `where`, `without`, `wrap`, and `zip`
  587. The non-chainable wrapper functions are:<br>
  588. `clone`, `cloneDeep`, `contains`, `escape`, `every`, `find`, `has`, `identity`, `indexOf`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`, `isEmpty`, `isEqual`, `isFinite`, `isFunction`, `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`, `isRegExp`, `isString`, `isUndefined`, `join`, `lastIndexOf`, `mixin`, `noConflict`, `pop`, `random`, `reduce`, `reduceRight`, `result`, `shift`, `size`, `some`, `sortedIndex`, `template`, `unescape`, and `uniqueId`
  589. The wrapper functions `first` and `last` return wrapped values when `n` is passed, otherwise they return unwrapped values.
  590. #### Arguments
  591. 1. `value` *(Mixed)*: The value to wrap in a `lodash` instance.
  592. #### Returns
  593. *(Object)*: Returns a `lodash` instance.
  594. * * *
  595. <!-- /div -->
  596. <!-- div -->
  597. ### <a id="_tapvalue-interceptor"></a>`_.tap(value, interceptor)`
  598. <a href="#_tapvalue-interceptor">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4874 "View in source") [&#x24C9;][1]
  599. Invokes `interceptor` with the `value` as the first argument, and then returns `value`. The purpose of this method is to "tap into" a method chain, in order to perform operations on intermediate results within the chain.
  600. #### Arguments
  601. 1. `value` *(Mixed)*: The value to pass to `interceptor`.
  602. 2. `interceptor` *(Function)*: The function to invoke.
  603. #### Returns
  604. *(Mixed)*: Returns `value`.
  605. #### Example
  606. ```js
  607. _([1, 2, 3, 4])
  608. .filter(function(num) { return num % 2 == 0; })
  609. .tap(alert)
  610. .map(function(num) { return num * num; })
  611. .value();
  612. // => // [2, 4] (alerted)
  613. // => [4, 16]
  614. ```
  615. * * *
  616. <!-- /div -->
  617. <!-- div -->
  618. ### <a id="_prototypetostring"></a>`_.prototype.toString()`
  619. <a href="#_prototypetostring">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4891 "View in source") [&#x24C9;][1]
  620. Produces the `toString` result of the wrapped value.
  621. #### Returns
  622. *(String)*: Returns the string result.
  623. #### Example
  624. ```js
  625. _([1, 2, 3]).toString();
  626. // => '1,2,3'
  627. ```
  628. * * *
  629. <!-- /div -->
  630. <!-- div -->
  631. ### <a id="_prototypevalueof"></a>`_.prototype.valueOf()`
  632. <a href="#_prototypevalueof">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L4908 "View in source") [&#x24C9;][1]
  633. Extracts the wrapped value.
  634. #### Aliases
  635. *value*
  636. #### Returns
  637. *(Mixed)*: Returns the wrapped value.
  638. #### Example
  639. ```js
  640. _([1, 2, 3]).valueOf();
  641. // => [1, 2, 3]
  642. ```
  643. * * *
  644. <!-- /div -->
  645. <!-- /div -->
  646. <!-- div -->
  647. ## `Collections Methods`
  648. <!-- div -->
  649. ### <a id="_atcollection--index1-index2-"></a>`_.at(collection [, index1, index2, ...])`
  650. <a href="#_atcollection--index1-index2-">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2167 "View in source") [&#x24C9;][1]
  651. Creates an array of elements from the specified indexes, or keys, of the `collection`. Indexes may be specified as individual arguments or as arrays of indexes.
  652. #### Arguments
  653. 1. `collection` *(Array|Object|String)*: The collection to iterate over.
  654. 2. `[index1, index2, ...]` *(Array|Number|String)*: The indexes of `collection` to retrieve, either as individual arguments or arrays.
  655. #### Returns
  656. *(Array)*: Returns a new array of elements corresponding to the provided indexes.
  657. #### Example
  658. ```js
  659. _.at(['a', 'b', 'c', 'd', 'e'], [0, 2, 4]);
  660. // => ['a', 'c', 'e']
  661. _.at(['moe', 'larry', 'curly'], 0, 2);
  662. // => ['moe', 'curly']
  663. ```
  664. * * *
  665. <!-- /div -->
  666. <!-- div -->
  667. ### <a id="_containscollection-target--fromindex0"></a>`_.contains(collection, target [, fromIndex=0])`
  668. <a href="#_containscollection-target--fromindex0">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2209 "View in source") [&#x24C9;][1]
  669. Checks if a given `target` element is present in a `collection` using strict equality for comparisons, i.e. `===`. If `fromIndex` is negative, it is used as the offset from the end of the collection.
  670. #### Aliases
  671. *include*
  672. #### Arguments
  673. 1. `collection` *(Array|Object|String)*: The collection to iterate over.
  674. 2. `target` *(Mixed)*: The value to check for.
  675. 3. `[fromIndex=0]` *(Number)*: The index to search from.
  676. #### Returns
  677. *(Boolean)*: Returns `true` if the `target` element is found, else `false`.
  678. #### Example
  679. ```js
  680. _.contains([1, 2, 3], 1);
  681. // => true
  682. _.contains([1, 2, 3], 1, 2);
  683. // => false
  684. _.contains({ 'name': 'moe', 'age': 40 }, 'moe');
  685. // => true
  686. _.contains('curly', 'ur');
  687. // => true
  688. ```
  689. * * *
  690. <!-- /div -->
  691. <!-- div -->
  692. ### <a id="_countbycollection--callbackidentity-thisarg"></a>`_.countBy(collection [, callback=identity, thisArg])`
  693. <a href="#_countbycollection--callbackidentity-thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2263 "View in source") [&#x24C9;][1]
  694. Creates an object composed of keys returned from running each element of the `collection` through the given `callback`. The corresponding value of each key is the number of times the key was returned by the `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*.
  695. If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element.
  696. If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`.
  697. #### Arguments
  698. 1. `collection` *(Array|Object|String)*: The collection to iterate over.
  699. 2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a property name or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively.
  700. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`.
  701. #### Returns
  702. *(Object)*: Returns the composed aggregate object.
  703. #### Example
  704. ```js
  705. _.countBy([4.3, 6.1, 6.4], function(num) { return Math.floor(num); });
  706. // => { '4': 1, '6': 2 }
  707. _.countBy([4.3, 6.1, 6.4], function(num) { return this.floor(num); }, Math);
  708. // => { '4': 1, '6': 2 }
  709. _.countBy(['one', 'two', 'three'], 'length');
  710. // => { '3': 2, '5': 1 }
  711. ```
  712. * * *
  713. <!-- /div -->
  714. <!-- div -->
  715. ### <a id="_everycollection--callbackidentity-thisarg"></a>`_.every(collection [, callback=identity, thisArg])`
  716. <a href="#_everycollection--callbackidentity-thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2315 "View in source") [&#x24C9;][1]
  717. Checks if the `callback` returns a truthy value for **all** elements of a `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*.
  718. If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element.
  719. If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`.
  720. #### Aliases
  721. *all*
  722. #### Arguments
  723. 1. `collection` *(Array|Object|String)*: The collection to iterate over.
  724. 2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a property name or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively.
  725. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`.
  726. #### Returns
  727. *(Boolean)*: Returns `true` if all elements pass the callback check, else `false`.
  728. #### Example
  729. ```js
  730. _.every([true, 1, null, 'yes'], Boolean);
  731. // => false
  732. var stooges = [
  733. { 'name': 'moe', 'age': 40 },
  734. { 'name': 'larry', 'age': 50 }
  735. ];
  736. // using "_.pluck" callback shorthand
  737. _.every(stooges, 'age');
  738. // => true
  739. // using "_.where" callback shorthand
  740. _.every(stooges, { 'age': 50 });
  741. // => false
  742. ```
  743. * * *
  744. <!-- /div -->
  745. <!-- div -->
  746. ### <a id="_filtercollection--callbackidentity-thisarg"></a>`_.filter(collection [, callback=identity, thisArg])`
  747. <a href="#_filtercollection--callbackidentity-thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2376 "View in source") [&#x24C9;][1]
  748. Examines each element in a `collection`, returning an array of all elements the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*.
  749. If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element.
  750. If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`.
  751. #### Aliases
  752. *select*
  753. #### Arguments
  754. 1. `collection` *(Array|Object|String)*: The collection to iterate over.
  755. 2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a property name or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively.
  756. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`.
  757. #### Returns
  758. *(Array)*: Returns a new array of elements that passed the callback check.
  759. #### Example
  760. ```js
  761. var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; });
  762. // => [2, 4, 6]
  763. var food = [
  764. { 'name': 'apple', 'organic': false, 'type': 'fruit' },
  765. { 'name': 'carrot', 'organic': true, 'type': 'vegetable' }
  766. ];
  767. // using "_.pluck" callback shorthand
  768. _.filter(food, 'organic');
  769. // => [{ 'name': 'carrot', 'organic': true, 'type': 'vegetable' }]
  770. // using "_.where" callback shorthand
  771. _.filter(food, { 'type': 'fruit' });
  772. // => [{ 'name': 'apple', 'organic': false, 'type': 'fruit' }]
  773. ```
  774. * * *
  775. <!-- /div -->
  776. <!-- div -->
  777. ### <a id="_findcollection--callbackidentity-thisarg"></a>`_.find(collection [, callback=identity, thisArg])`
  778. <a href="#_findcollection--callbackidentity-thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2443 "View in source") [&#x24C9;][1]
  779. Examines each element in a `collection`, returning the first that the `callback` returns truthy for. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*.
  780. If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element.
  781. If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`.
  782. #### Aliases
  783. *detect*
  784. #### Arguments
  785. 1. `collection` *(Array|Object|String)*: The collection to iterate over.
  786. 2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a property name or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively.
  787. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`.
  788. #### Returns
  789. *(Mixed)*: Returns the element that passed the callback check, else `undefined`.
  790. #### Example
  791. ```js
  792. var even = _.find([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; });
  793. // => 2
  794. var food = [
  795. { 'name': 'apple', 'organic': false, 'type': 'fruit' },
  796. { 'name': 'banana', 'organic': true, 'type': 'fruit' },
  797. { 'name': 'beet', 'organic': false, 'type': 'vegetable' },
  798. { 'name': 'carrot', 'organic': true, 'type': 'vegetable' }
  799. ];
  800. // using "_.where" callback shorthand
  801. var veggie = _.find(food, { 'type': 'vegetable' });
  802. // => { 'name': 'beet', 'organic': false, 'type': 'vegetable' }
  803. // using "_.pluck" callback shorthand
  804. var healthy = _.find(food, 'organic');
  805. // => { 'name': 'banana', 'organic': true, 'type': 'fruit' }
  806. ```
  807. * * *
  808. <!-- /div -->
  809. <!-- div -->
  810. ### <a id="_foreachcollection--callbackidentity-thisarg"></a>`_.forEach(collection [, callback=identity, thisArg])`
  811. <a href="#_foreachcollection--callbackidentity-thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2478 "View in source") [&#x24C9;][1]
  812. Iterates over a `collection`, executing the `callback` for each element in the `collection`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*. Callbacks may exit iteration early by explicitly returning `false`.
  813. #### Aliases
  814. *each*
  815. #### Arguments
  816. 1. `collection` *(Array|Object|String)*: The collection to iterate over.
  817. 2. `[callback=identity]` *(Function)*: The function called per iteration.
  818. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`.
  819. #### Returns
  820. *(Array, Object, String)*: Returns `collection`.
  821. #### Example
  822. ```js
  823. _([1, 2, 3]).forEach(alert).join(',');
  824. // => alerts each number and returns '1,2,3'
  825. _.forEach({ 'one': 1, 'two': 2, 'three': 3 }, alert);
  826. // => alerts each number value (order is not guaranteed)
  827. ```
  828. * * *
  829. <!-- /div -->
  830. <!-- div -->
  831. ### <a id="_groupbycollection--callbackidentity-thisarg"></a>`_.groupBy(collection [, callback=identity, thisArg])`
  832. <a href="#_groupbycollection--callbackidentity-thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2528 "View in source") [&#x24C9;][1]
  833. Creates an object composed of keys returned from running each element of the `collection` through the `callback`. The corresponding value of each key is an array of elements passed to `callback` that returned the key. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*.
  834. If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element.
  835. If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`
  836. #### Arguments
  837. 1. `collection` *(Array|Object|String)*: The collection to iterate over.
  838. 2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a property name or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively.
  839. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`.
  840. #### Returns
  841. *(Object)*: Returns the composed aggregate object.
  842. #### Example
  843. ```js
  844. _.groupBy([4.2, 6.1, 6.4], function(num) { return Math.floor(num); });
  845. // => { '4': [4.2], '6': [6.1, 6.4] }
  846. _.groupBy([4.2, 6.1, 6.4], function(num) { return this.floor(num); }, Math);
  847. // => { '4': [4.2], '6': [6.1, 6.4] }
  848. // using "_.pluck" callback shorthand
  849. _.groupBy(['one', 'two', 'three'], 'length');
  850. // => { '3': ['one', 'two'], '5': ['three'] }
  851. ```
  852. * * *
  853. <!-- /div -->
  854. <!-- div -->
  855. ### <a id="_invokecollection-methodname--arg1-arg2-"></a>`_.invoke(collection, methodName [, arg1, arg2, ...])`
  856. <a href="#_invokecollection-methodname--arg1-arg2-">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2561 "View in source") [&#x24C9;][1]
  857. Invokes the method named by `methodName` on each element in the `collection`, returning an array of the results of each invoked method. Additional arguments will be passed to each invoked method. If `methodName` is a function, it will be invoked for, and `this` bound to, each element in the `collection`.
  858. #### Arguments
  859. 1. `collection` *(Array|Object|String)*: The collection to iterate over.
  860. 2. `methodName` *(Function|String)*: The name of the method to invoke or the function invoked per iteration.
  861. 3. `[arg1, arg2, ...]` *(Mixed)*: Arguments to invoke the method with.
  862. #### Returns
  863. *(Array)*: Returns a new array of the results of each invoked method.
  864. #### Example
  865. ```js
  866. _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
  867. // => [[1, 5, 7], [1, 2, 3]]
  868. _.invoke([123, 456], String.prototype.split, '');
  869. // => [['1', '2', '3'], ['4', '5', '6']]
  870. ```
  871. * * *
  872. <!-- /div -->
  873. <!-- div -->
  874. ### <a id="_mapcollection--callbackidentity-thisarg"></a>`_.map(collection [, callback=identity, thisArg])`
  875. <a href="#_mapcollection--callbackidentity-thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2613 "View in source") [&#x24C9;][1]
  876. Creates an array of values by running each element in the `collection` through the `callback`. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index|key, collection)*.
  877. If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element.
  878. If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`.
  879. #### Aliases
  880. *collect*
  881. #### Arguments
  882. 1. `collection` *(Array|Object|String)*: The collection to iterate over.
  883. 2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a property name or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively.
  884. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`.
  885. #### Returns
  886. *(Array)*: Returns a new array of the results of each `callback` execution.
  887. #### Example
  888. ```js
  889. _.map([1, 2, 3], function(num) { return num * 3; });
  890. // => [3, 6, 9]
  891. _.map({ 'one': 1, 'two': 2, 'three': 3 }, function(num) { return num * 3; });
  892. // => [3, 6, 9] (order is not guaranteed)
  893. var stooges = [
  894. { 'name': 'moe', 'age': 40 },
  895. { 'name': 'larry', 'age': 50 }
  896. ];
  897. // using "_.pluck" callback shorthand
  898. _.map(stooges, 'name');
  899. // => ['moe', 'larry']
  900. ```
  901. * * *
  902. <!-- /div -->
  903. <!-- div -->
  904. ### <a id="_maxcollection--callbackidentity-thisarg"></a>`_.max(collection [, callback=identity, thisArg])`
  905. <a href="#_maxcollection--callbackidentity-thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2670 "View in source") [&#x24C9;][1]
  906. Retrieves the maximum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, collection)*.
  907. If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element.
  908. If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`.
  909. #### Arguments
  910. 1. `collection` *(Array|Object|String)*: The collection to iterate over.
  911. 2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a property name or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively.
  912. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`.
  913. #### Returns
  914. *(Mixed)*: Returns the maximum value.
  915. #### Example
  916. ```js
  917. _.max([4, 2, 8, 6]);
  918. // => 8
  919. var stooges = [
  920. { 'name': 'moe', 'age': 40 },
  921. { 'name': 'larry', 'age': 50 }
  922. ];
  923. _.max(stooges, function(stooge) { return stooge.age; });
  924. // => { 'name': 'larry', 'age': 50 };
  925. // using "_.pluck" callback shorthand
  926. _.max(stooges, 'age');
  927. // => { 'name': 'larry', 'age': 50 };
  928. ```
  929. * * *
  930. <!-- /div -->
  931. <!-- div -->
  932. ### <a id="_mincollection--callbackidentity-thisarg"></a>`_.min(collection [, callback=identity, thisArg])`
  933. <a href="#_mincollection--callbackidentity-thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2739 "View in source") [&#x24C9;][1]
  934. Retrieves the minimum value of an `array`. If `callback` is passed, it will be executed for each value in the `array` to generate the criterion by which the value is ranked. The `callback` is bound to `thisArg` and invoked with three arguments; *(value, index, collection)*.
  935. If a property name is passed for `callback`, the created "_.pluck" style callback will return the property value of the given element.
  936. If an object is passed for `callback`, the created "_.where" style callback will return `true` for elements that have the propeties of the given object, else `false`.
  937. #### Arguments
  938. 1. `collection` *(Array|Object|String)*: The collection to iterate over.
  939. 2. `[callback=identity]` *(Function|Object|String)*: The function called per iteration. If a property name or object is passed, it will be used to create a "_.pluck" or "_.where" style callback, respectively.
  940. 3. `[thisArg]` *(Mixed)*: The `this` binding of `callback`.
  941. #### Returns
  942. *(Mixed)*: Returns the minimum value.
  943. #### Example
  944. ```js
  945. _.min([4, 2, 8, 6]);
  946. // => 2
  947. var stooges = [
  948. { 'name': 'moe', 'age': 40 },
  949. { 'name': 'larry', 'age': 50 }
  950. ];
  951. _.min(stooges, function(stooge) { return stooge.age; });
  952. // => { 'name': 'moe', 'age': 40 };
  953. // using "_.pluck" callback shorthand
  954. _.min(stooges, 'age');
  955. // => { 'name': 'moe', 'age': 40 };
  956. ```
  957. * * *
  958. <!-- /div -->
  959. <!-- div -->
  960. ### <a id="_pluckcollection-property"></a>`_.pluck(collection, property)`
  961. <a href="#_pluckcollection-property">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2789 "View in source") [&#x24C9;][1]
  962. Retrieves the value of a specified property from all elements in the `collection`.
  963. #### Arguments
  964. 1. `collection` *(Array|Object|String)*: The collection to iterate over.
  965. 2. `property` *(String)*: The property to pluck.
  966. #### Returns
  967. *(Array)*: Returns a new array of property values.
  968. #### Example
  969. ```js
  970. var stooges = [
  971. { 'name': 'moe', 'age': 40 },
  972. { 'name': 'larry', 'age': 50 }
  973. ];
  974. _.pluck(stooges, 'name');
  975. // => ['moe', 'larry']
  976. ```
  977. * * *
  978. <!-- /div -->
  979. <!-- div -->
  980. ### <a id="_reducecollection--callbackidentity-accumulator-thisarg"></a>`_.reduce(collection [, callback=identity, accumulator, thisArg])`
  981. <a href="#_reducecollection--callbackidentity-accumulator-thisarg">#</a> [&#x24C8;](https://github.com/bestiejs/lodash/blob/master/lodash.js#L2821 "View in source") [&#x24C9;][1]
  982. Reduces a `collection` to a value that is the accumulated result of running each element in the `collection` through the `callback`, where each successive `callback` execution consumes the return value of the previous execution. If `accumulator` is not passed, the first element of the `collection` will be used as the initial `accumulator` value. The `callback` is bound to `thisArg` and invoked with four arguments; *(accumulator, value, index|key, collection)*.
  983. #### Aliases
  984. *foldl, inject*
  985. #### Arguments
  986. 1. `collection` *(Array|Object|String)*: The collection to iterate over.
  987. 2. `[callback=identity]` *(Function)*: The function called per iteration.
  988. 3. `[accumulator]` *(Mixed)*: Ini…

Large files files are truncated, but you can click here to view the full file