{"id":29275887,"url":"https://github.com/peterroe/collect-es","last_synced_at":"2025-07-05T07:11:29.372Z","repository":{"id":45802696,"uuid":"514638231","full_name":"peterroe/collect-es","owner":"peterroe","description":"collects.js exported as ES modules.","archived":false,"fork":false,"pushed_at":"2023-12-14T20:46:28.000Z","size":550,"stargazers_count":4,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2023-12-14T21:40:11.613Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peterroe.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-16T17:05:09.000Z","updated_at":"2023-11-16T20:58:51.000Z","dependencies_parsed_at":"2022-07-17T12:00:41.481Z","dependency_job_id":null,"html_url":"https://github.com/peterroe/collect-es","commit_stats":null,"previous_names":[],"tags_count":1,"template":null,"template_full_name":null,"purl":"pkg:github/peterroe/collect-es","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterroe%2Fcollect-es","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterroe%2Fcollect-es/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterroe%2Fcollect-es/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterroe%2Fcollect-es/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterroe","download_url":"https://codeload.github.com/peterroe/collect-es/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterroe%2Fcollect-es/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263699784,"owners_count":23497963,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-05T07:11:24.504Z","updated_at":"2025-07-05T07:11:29.363Z","avatar_url":"https://github.com/peterroe.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"./collect.svg\" alt=\"collect.js\"\u003e\n\u003c/p\u003e\n\n\u003e Convenient and dependency free wrapper for working with arrays and objects\n\n#### Install\n\n```bash\nnpm install collect-es\n```\n\n#### Usage\n\n```ts\n// example\nimport collect from 'collect-es'\n\nconst collection = collect([\n  { name: 'Desk', price: 200 },\n  { name: 'Chair', price: 100 },\n  { name: 'Bookcase', price: 150 },\n])\n\nconst sorted = collection.sortBy('price')\n\nsorted.all()\n\n// [\n//   { name: 'Chair', price: 100 },\n//   { name: 'Bookcase', price: 150 },\n//   { name: 'Desk', price: 200 },\n// ]\n```\n\n### API\n- [API](#api)\n- [Strictness and comparisons](#strictness-and-comparisons)\n    - [Methods that have not been implemented:](#methods-that-have-not-been-implemented)\n  - [`all()`](#all)\n  - [`average()`](#average)\n  - [`avg()`](#avg)\n  - [`chunk()`](#chunk)\n  - [`collapse()`](#collapse)\n  - [`combine()`](#combine)\n  - [`concat()`](#concat)\n  - [`contains()`](#contains)\n  - [`containsOneItem()`](#containsoneitem)\n  - [`count()`](#count)\n  - [`countBy()`](#countby)\n  - [`crossJoin()`](#crossjoin)\n  - [`dd()`](#dd)\n  - [`diff()`](#diff)\n  - [`diffAssoc()`](#diffassoc)\n  - [`diffKeys()`](#diffkeys)\n  - [`doesntContain()`](#doesntcontain)\n  - [`dump()`](#dump)\n  - [`duplicates()`](#duplicates)\n  - [`each()`](#each)\n  - [`eachSpread()`](#eachspread)\n  - [`every()`](#every)\n  - [`except()`](#except)\n  - [`filter()`](#filter)\n  - [`first()`](#first)\n  - [`firstOrFail()`](#firstorfail)\n  - [`firstWhere()`](#firstwhere)\n  - [`flatMap()`](#flatmap)\n  - [`flatten()`](#flatten)\n  - [`flip()`](#flip)\n  - [`forPage()`](#forpage)\n  - [`forget()`](#forget)\n  - [`get()`](#get)\n  - [`groupBy()`](#groupby)\n  - [`has()`](#has)\n  - [`implode()`](#implode)\n  - [`intersect()`](#intersect)\n  - [`intersectByKeys()`](#intersectbykeys)\n  - [`isEmpty()`](#isempty)\n  - [`isNotEmpty()`](#isnotempty)\n  - [`join()`](#join)\n  - [`keyBy()`](#keyby)\n  - [`keys()`](#keys)\n  - [`last()`](#last)\n  - [`macro()`](#macro)\n  - [`make()`](#make)\n  - [`map()`](#map)\n  - [`mapInto()`](#mapinto)\n  - [`mapSpread()`](#mapspread)\n  - [`mapToDictionary()`](#maptodictionary)\n  - [`mapToGroups()`](#maptogroups)\n  - [`mapWithKeys()`](#mapwithkeys)\n  - [`max()`](#max)\n  - [`median()`](#median)\n  - [`merge()`](#merge)\n  - [`mergeRecursive()`](#mergerecursive)\n  - [`min()`](#min)\n  - [`mode()`](#mode)\n  - [`nth()`](#nth)\n  - [`only()`](#only)\n  - [`pad()`](#pad)\n  - [`partition()`](#partition)\n  - [`pipe()`](#pipe)\n  - [`pluck()`](#pluck)\n  - [`pop()`](#pop)\n  - [`prepend()`](#prepend)\n  - [`pull()`](#pull)\n  - [`push()`](#push)\n  - [`put()`](#put)\n  - [`random()`](#random)\n  - [`reduce()`](#reduce)\n  - [`reject()`](#reject)\n  - [`replace()`](#replace)\n  - [`replaceRecursive()`](#replacerecursive)\n  - [`reverse()`](#reverse)\n  - [`search()`](#search)\n  - [`shift()`](#shift)\n  - [`shuffle()`](#shuffle)\n  - [`skip()`](#skip)\n  - [`skipUntil()`](#skipuntil)\n  - [`skipWhile()`](#skipwhile)\n  - [`slice()`](#slice)\n  - [`sole()`](#sole)\n  - [`some()`](#some)\n  - [`sort()`](#sort)\n  - [`sortBy()`](#sortby)\n  - [`sortByDesc()`](#sortbydesc)\n  - [`sortDesc()`](#sortdesc)\n  - [`sortKeys()`](#sortkeys)\n  - [`sortKeysDesc()`](#sortkeysdesc)\n  - [`splice()`](#splice)\n  - [`split()`](#split)\n  - [`sum()`](#sum)\n  - [`take()`](#take)\n  - [`takeUntil()`](#takeuntil)\n  - [`takeWhile()`](#takewhile)\n  - [`tap()`](#tap)\n  - [`times()`](#times)\n  - [`toArray()`](#toarray)\n  - [`toJson()`](#tojson)\n  - [`transform()`](#transform)\n  - [`undot()`](#undot)\n  - [`union()`](#union)\n  - [`unique()`](#unique)\n  - [`unless()`](#unless)\n  - [`unlessEmpty()`](#unlessempty)\n  - [`unlessNotEmpty()`](#unlessnotempty)\n  - [`unwrap()`](#unwrap)\n  - [`values()`](#values)\n  - [`when()`](#when)\n  - [`whenEmpty()`](#whenempty)\n  - [`whenNotEmpty()`](#whennotempty)\n  - [`where()`](#where)\n  - [`whereBetween()`](#wherebetween)\n  - [`whereIn()`](#wherein)\n  - [`whereInstanceOf()`](#whereinstanceof)\n  - [`whereNotBetween()`](#wherenotbetween)\n  - [`whereNotIn()`](#wherenotin)\n  - [`whereNotNull()`](#wherenotnull)\n  - [`whereNull()`](#wherenull)\n  - [`wrap()`](#wrap)\n  - [`zip()`](#zip)\n- [Contribute](#contribute)\n- [License](#license)\n\n### Strictness and comparisons\n\nAll comparisons in `collect.js` are done using strict equality. Using loose equality comparisons are generally frowned upon in JavaScript. Laravel only performs \"loose\" comparisons by default and offer several \"strict\" comparison methods. These methods have not been implemented in `collect.js` because all methods are strict by default.\n\n##### Methods that have not been implemented:\n\n- ~~`containsStrict`~~ use `contains()`\n- ~~`duplicatesStrict`~~ use `duplicates()`\n- ~~`uniqueStrict`~~ use `unique()`\n- ~~`whereStrict`~~ use `where()`\n- ~~`whereInStrict`~~ use `whereIn()`\n- ~~`whereNotInStrict`~~ use `whereNotIn()`\n\n#### `all()`\n\nThe all method returns the underlying array or object represented by the collection:\n\n```js\ncollect([1, 2, 3]).all()\n\n// [1, 2, 3]\n```\n\n```js\ncollect({\n  firstname: 'Sadio',\n  lastname: 'Mané',\n}).all()\n\n// {\n//   firstname: 'Sadio',\n//   lastname: 'Mané',\n// }\n```\n\n\n#### `average()`\n\nAlias for the [`avg()`](#avg) method\n\n#### `avg()`\n\nThe avg method returns the average of all items in the collection:\n\n```js\ncollect([1, 3, 3, 7]).avg()\n\n// 3.5\n```\n\nIf the collection contains nested arrays or objects, you should pass a key to use for determining which values to calculate the average:\n\n```js\nconst collection = collect([\n  {\n    name: 'My story',\n    pages: 176,\n  },\n  {\n    name: 'Fantastic Beasts and Where to Find Them',\n    pages: 1096,\n  },\n])\n\ncollection.avg('pages')\n\n// 636\n```\n\nYou may also define a callback function\n\n```js\nconst collection = collect([\n  {\n    name: 'My story',\n    pages: 176,\n  },\n  {\n    name: 'Fantastic Beasts and Where to Find Them',\n    pages: 1096,\n  },\n])\n\ncollection.avg(book =\u003e book.pages)\n\n// 636\n```\n\n#### `chunk()`\n\nThe chunk method breaks the collection into multiple, smaller collections of a given size:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5, 6, 7])\n\nconst chunks = collection.chunk(4)\n\nchunks.all()\n\n// [[1, 2, 3, 4], [5, 6, 7]]\n```\n\n#### `collapse()`\n\nThe collapse method collapses a collection of arrays into a single, flat collection:\n\n```js\nconst collection = collect([[1], [{}, 5, {}], ['xoxo']])\n\nconst collapsed = collection.collapse()\n\ncollapsed.all()\n\n// [1, {}, 5, {}, 'xoxo']\n```\n\n```js\nconst collection = collect([[1, 2, 3], [4, 5, 6], [7, 8, 9]])\n\nconst collapsed = collection.collapse()\n\ncollapsed.all()\n\n// [1, 2, 3, 4, 5, 6, 7, 8, 9]\n```\n\n#### `combine()`\n\nThe combine method combines the keys of the collection with the values of another array or collection:\n\n```js\nconst collection = collect(['name', 'number'])\n\nconst combine = collection.combine(['Mohamed Salah', 11])\n\ncombine.all()\n\n// {\n//   name: 'Mohamed Salah',\n//   number: 11\n// }\n```\n\n#### `concat()`\n\nThe concat method is used to merge two or more collections/arrays/objects:\n\n_You can also `concat()` an array of objects, or a multidimensional array_\n\n```js\nconst collection = collect([1, 2, 3])\n\nlet concatenated = collection.concat(['a', 'b', 'c'])\n\nconcatenated = concatenated.concat({\n  name: 'Mohamed Salah',\n  number: 11,\n})\n\nconcatenated.all()\n\n// [1, 2, 3, 'a', 'b', 'c', 'Mohamed Salah', 11]\n```\n\n#### `contains()`\n\nThe contains method determines whether the collection contains a given item:\n\n```js\nconst collection = collect({\n  name: 'Mohamed Salah',\n  number: 11,\n})\n\ncollection.contains('name')\n// true\n\ncollection.contains('age')\n// false\n\ncollection.contains('Mohamed Salah')\n// true\n```\n\nYou may also work with arrays\n\n```js\nconst collection = collect([1, 2, 3])\n\ncollection.contains(3)\n// true\n```\n\nYou may also pass a key / value pair to the contains method, which will determine if the given pair exists in the collection:\n\n```js\nconst collection = collect({\n  name: 'Mohamed Salah',\n  number: 11,\n})\n\ncollection.contains('name', 'Steve Jobs')\n// false\n```\n\nFinally, you may also pass a callback to the contains method to perform your own truth test:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\ncollection.contains((value, key) =\u003e value \u003e 5)\n\n// false\n```\n\n#### `containsOneItem()`\n\nThe containsOneItem method returns true if the collection contains exactly one item; otherwise, false is returned:\n\n```js\ncollect([1]).containsOneItem()\n// true\n\ncollect({ firstname: 'Luis' }).containsOneItem()\n// true\n\ncollect('value').containsOneItem()\n// true\n\ncollect([1, 2, 3]).containsOneItem()\n//  false\n\ncollect({ firstname: 'Luis', lastname: 'Díaz' }).containsOneItem()\n// false\n\ncollect().containsOneItem()\n// false\n\ncollect([]).containsOneItem()\n// false\n\ncollect({}).containsOneItem()\n// false\n```\n\n\n#### `count()`\n\nThe count method returns the total number of items in the collection:\n\n```js\nconst collection = collect([1, 2, 3, 4])\n\ncollection.count()\n\n// 4\n```\n\n#### `countBy()`\n\nThe countBy method counts the occurences of values in the collection. By default, the method counts the occurrences of every element:\n\n```js\nconst collection = collect([1, 2, 2, 2, 3])\n\nconst counted = collection.countBy()\n\ncounted.all()\n\n// {\n//   1: 1,\n//   2: 3,\n//   3: 1,\n// }\n```\n\nHowever, you pass a callback to the countBy method to count all items by a custom value:\n\n```js\nconst collection = collect([\n  'mohamed.salah@gmail.com',\n  'sadio.mane@yahoo.com',\n  'roberto.firmino@gmail.com',\n])\n\nconst counted = collection.countBy(email =\u003e email.split('@')[1])\n\ncounted.all()\n\n// {\n//   'gmail.com': 2,\n//   'yahoo.com': 1,\n// }\n```\n\n#### `crossJoin()`\n\nThe crossJoin method cross joins the collection with the given array or collection, returning all possible permutations:\n\n```js\nconst collection = collect([1, 2])\n\nconst joined = collection.crossJoin(['a', 'b'])\n\njoined.all()\n\n// [\n//   [1, 'a'],\n//   [1, 'b'],\n//   [2, 'a'],\n//   [2, 'b'],\n// ]\n```\n\n#### `dd()`\n\nThe dd method will `console.log` the collection and exit the current process:\n\n```js\nconst collection = collect([1, 2, 3]).dd()\n\n// Collection { items: [ 1, 2, 3 ] }\n// (Exits node.js process)\n```\n\n#### `diff()`\n\nThe diff method compares the collection against another collection or a plain array based on its values. This method will return the values in the original collection that are not present in the given collection:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\nconst diff = collection.diff([1, 2, 3, 9])\n\ndiff.all()\n\n// [4, 5]\n```\n\n#### `diffAssoc()`\n\nThe diffAssoc method compares the collection against another collection or a plain object based on its keys and values.\nThis method will return the key / value pairs in the original collection that are not present in the given collection:\n\n```js\nconst collection = collect({\n  color: 'orange',\n  type: 'fruit',\n  remain: 6,\n})\n\nconst diff = collection.diffAssoc({\n  color: 'yellow',\n  type: 'fruit',\n  remain: 3,\n  used: 6,\n})\n\ndiff.all()\n\n// { color: 'orange', remain: 6 };\n```\n\n#### `diffKeys()`\n\nThe diffKeys method compares the collection against another collection or a plain object based on its keys. This method will return the key / value pairs in the original collection that are not present in the given collection:\n\n```js\nconst collection = collect({\n  a: 'a',\n  b: 'b',\n  c: 'c',\n  d: 'd',\n})\n\nconst diff = collection.diffKeys({\n  b: 'b',\n  d: 'd',\n})\n\ndiff.all()\n\n// { a: 'a', c: 'c' }\n```\n\n#### `doesntContain()`\n\nThe `doesntContain` method determines whether the collection does not contain a given item. You may pass a closure to the `doesntContain` method to determine if an element does not exist in the collection matching a given truth test:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\ncollection.doesntContain(value =\u003e value \u003c 5)\n\n// false\n```\n\n```js\nconst collection = collect([1, 2, 3])\n\ncollection.doesntContain(4)\n// true\n```\n\nYou may also use `doesntContain` on object based collections:\n\n```js\nconst collection = collect({\n  name: 'Mohamed Salah',\n  number: 11,\n})\n\ncollection.doesntContain('Mohamed Salah')\n// false\n\ncollection.doesntContain('Sadio Mané')\n// true\n```\n\nYou may also pass a key / value pair to the contains method, which will determine if the given pair exists in the collection:\n\n```js\nconst collection = collect({\n  name: 'Mohamed Salah',\n  number: 11,\n})\n\ncollection.doesntContain('name', 'Sadio Mané')\n// true\n```\n\n#### `dump()`\n\nThe dump method outputs the results at that moment and then continues processing:\n\n```js\ncollect([1, 2, 3, 4])\n  .dump()\n  .map(item =\u003e item * 2)\n  .dump()\n\n// Collection { items: [ 1, 2, 3, 4 ] }\n// Collection { items: [ 2, 4, 6, 8 ] }\n```\n\n#### `duplicates()`\n\nThe duplicates method retrieves and returns duplicate values from the collection:\n\n```js\nconst collection = collect(['a', 'b', 'a', 'c', 'b'])\n\nconst duplicates = collection.duplicates()\n\nduplicates.all()\n\n// { 2: 'a', 4: 'b' }\n```\n\n#### `each()`\n\nThe each method iterates over the items in the collection and passes each item to a callback:\n\n```js\nlet sum = 0\n\nconst collection = collect([1, 3, 3, 7])\n\ncollection.each((item) =\u003e {\n  sum += item\n})\n\n// console.log(sum);\n// 14\n```\n\nIf you would like to stop iterating through the items, you may return false from your callback:\n\n```js\nlet sum = 0\n\nconst collection = collect([1, 3, 3, 7])\n\ncollection.each((item) =\u003e {\n  sum += item\n\n  if (sum \u003e 5)\n    return false\n\n})\n\n// console.log(sum);\n// 7\n```\n\n#### `eachSpread()`\n\nThe eachSpread method iterates over the collection's items, passing each nested item value into the given callback:\n\n```js\nconst collection = collect([['John Doe', 35], ['Jane Doe', 33]])\n\ncollection.eachSpread((name, age) =\u003e {\n  //\n})\n```\n\nYou may stop iterating through the items by returning false from the callback:\n\n```js\ncollection.eachSpread((name, age) =\u003e false)\n```\n\n#### `every()`\n\nThe every method may be used to verify that all elements of a collection pass a given truth test:\n\n```js\ncollect([1, 2, 3, 4]).every((value, key) =\u003e value \u003e 2)\n\n// false\n```\n\n#### `except()`\n\nThe except method returns all items in the collection except for those with the specified keys:\n\n```js\nconst collection = collect({\n  product_id: 1,\n  price: 100,\n  discount: false,\n})\n\nconst filtered = collection.except(['price', 'discount'])\n\nfiltered.all()\n\n// { product_id: 1 }\n```\n\n```js\ncollect([1, 2, 3, 4])\n  .except([2, 12])\n  .all()\n\n// [1, 3, 4]\n```\n\n\u003e For the inverse of `except`, see the `only` method.\n\n#### `filter()`\n\nThe filter method filters the collection using the given callback, keeping only those items that pass a given truth test:\n\n```js\nconst collection = collect([1, 2, 3, 4])\n\nconst filtered = collection.filter((value, key) =\u003e value \u003e 2)\n\nfiltered.all()\n\n// [3, 4]\n```\n\nIf no callback is supplied, all entries of the collection that are equivalent to `false` will be removed:\n\n```js\nconst collection = collect([\n  0,\n  1,\n  2,\n  null,\n  3,\n  4,\n  undefined,\n  5,\n  6,\n  7,\n  [],\n  8,\n  9,\n  {},\n  10,\n])\n\nconst filtered = collection.filter()\n\nfiltered.all()\n\n// [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n```\n\n\u003e For the inverse of `filter`, see the `reject` method.\n\n#### `first()`\n\nThe first method returns the first element in the collection that passes a given truth test:\n\n```js\ncollect([1, 2, 3, 4]).first(item =\u003e item \u003e 1)\n\n// 2\n```\n\nYou may also call the first method with no arguments to get the first element in the collection. If the collection is empty, null is returned:\n\n```js\ncollect([1, 2, 3, 4]).first()\n\n// 1\n```\n\n#### `firstOrFail()`\n\nThe firstOrFail method returns the first element in the collection, or throws an error if there are no elements:\n\n```js\ncollect([1, 2, 3, 4]).firstOrFail(item =\u003e item \u003e 1)\n\n// 2\n```\n\n```js\ncollect([1, 2, 3, 4]).firstOrFail(item =\u003e item \u003e 4)\n\n// Error ('Item not found.') is thrown.\n```\n\nYou may also call the firstOrFail method with no arguments to get the first element in the collection. If the collection is empty, an error is thrown:\n\n```js\ncollect([1, 2, 3, 4]).firstOrFail()\n\n// 1\n```\n\n```js\ncollect().firstOrFail()\n\n// Error ('Item not found.') is thrown.\n```\n\nLike the where method, you may also pass an attribute, operator, and value:\n\n```js\nconst collection = collect([\n  { product: 'Desk', price: 200, discounted: true },\n  { product: 'Chair', price: 100, discounted: true },\n  { product: 'Bookcase', price: 150, discounted: true },\n  { product: 'Door', price: 100 },\n])\n\ncollection.firstOrFail('product', '=', 'Desk')\n\n// { product: 'Desk', price: 200, discounted: true }\n```\n\n\n#### `firstWhere()`\n\nThe firstWhere method returns the first element in the collection with the given key / value pair:\n\n```js\nconst collection = collect([\n  { name: 'Regena', age: 12 },\n  { name: 'Linda', age: 14 },\n  { name: 'Diego', age: 23 },\n  { name: 'Linda', age: 84 },\n])\n\ncollection.firstWhere('name', 'Linda')\n\n// { name: 'Linda', age: 14 }\n```\n\n#### `flatMap()`\n\nThe flatMap method iterates through the collection and passes each value to the given callback. The callback is free to modify the item and return it, thus forming a new collection of modified items. Then, the array is flattened by a level:\n\n```js\nconst collection = collect([\n  {\n    name: 'Sadio Mané',\n    number: 10,\n  },\n  {\n    name: 'Mohamed Salah',\n    number: 11,\n  },\n])\n\nconst flatMapped = collection.flatMap(value =\u003e value.name.toUpperCase())\n\nflatMapped.all()\n\n// ['SADIO MANÉ', 'MOHAMED SALAH']\n```\n\n#### `flatten()`\n\nThe flatten method flattens a multi-dimensional collection into a single dimension:\n\n```js\nconst collection = collect({\n  club: 'Liverpool',\n  players: ['Salah', 'Firmino', 'Mané'],\n})\n\nconst flattened = collection.flatten()\n\nflattened.all()\n\n// ['Liverpool', 'Salah', 'Firmino', 'Mané'];\n```\n\nYou may optionally pass the function a \"depth\" argument:\n\n```js\nconst collection = collect({\n  Apple: [\n    {\n      name: 'iPhone 6S',\n      brand: 'Apple',\n    },\n  ],\n  Samsung: [\n    {\n      name: 'Galaxy S7',\n      brand: 'Samsung',\n    },\n  ],\n})\n\nconst flattened = collection.flatten(1)\n\nflattened.all()\n\n// [\n//   { name: 'iPhone 6S', brand: 'Apple' },\n//   { name: 'Galaxy S7', brand: 'Samsung' },\n// ]\n```\n\nIn this example, calling flatten without providing the depth would have also flattened the nested arrays, resulting in `['iPhone 6S', 'Apple', 'Galaxy S7', 'Samsung']`. Providing a depth allows you to restrict the levels of nested arrays that will be flattened.\n\n#### `flip()`\n\nThe flip method swaps the collection's keys with their corresponding values:\n\n```js\nconst collection = collect({\n  name: 'Sadio Mané',\n  number: 10,\n})\n\nconst flipped = collection.flip()\n\nflipped.all()\n\n// {\n//   'Sadio Mané': 'name',\n//   '10': 'number',\n// }\n```\n\n#### `forPage()`\n\nThe forPage method returns a new collection containing the items that would be present on a given page number. The method accepts the page number as its first argument and the number of items to show per page as its second argument:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5, 6, 7, 8, 9])\n\nconst forPage = collection.forPage(2, 3)\n\nforPage.all()\n\n// [4, 5, 6]\n```\n\n#### `forget()`\n\nThe forget method removes an item from the collection by its key:\n\n```js\nconst collection = collect({\n  name: 'Sadio Mané',\n  number: 10,\n})\n\ncollection.forget('number')\n\ncollection.all()\n\n// {\n//   name: 'Sadio Mané',\n// }\n```\n\n\u003e Unlike most other collection methods, forget does not return a new modified collection; it modifies the collection it is called on.\n\n#### `get()`\n\nThe get method returns the item at a given key or index. If the key or index does not exist, `null` is returned:\n\n```js\nconst collection = collect({\n  firstname: 'Mohamed',\n  lastname: 'Salah',\n})\n\ncollection.get('lastname')\n\n// Salah\n\ncollection.get('middlename')\n\n// null\n```\n\n```js\nconst collection = collect(['a', 'b', 'c'])\n\ncollection.get(1)\n\n// b\n```\n\nYou may optionally pass a default value as the second argument:\n\n```js\nconst collection = collect({\n  firstname: 'Mohamed',\n  lastname: 'Salah',\n})\n\ncollection.get('middlename', 'default-value')\n// default-value\n```\n\nYou may even pass a callback as the default value. The result of the callback will be returned if the specified key does not exist:\n\n```js\nconst collection = collect({\n  firstname: 'Mohamed',\n  lastname: 'Salah',\n})\n\ncollection.get('middlename', () =\u003e 'default-value')\n\n// default-value\n```\n\n#### `groupBy()`\n\nThe groupBy method groups the collection's items into multiple collections by a given key:\n\n\u003e If you want to group the collection by keys as a plain object, see [mapToGroups](mapToGroups)\n\n```js\nconst collection = collect([\n  {\n    product: 'Chair',\n    manufacturer: 'IKEA',\n  },\n  {\n    product: 'Desk',\n    manufacturer: 'IKEA',\n  },\n  {\n    product: 'Chair',\n    manufacturer: 'Herman Miller',\n  },\n])\n\nconst grouped = collection.groupBy('manufacturer')\n\ngrouped.all()\n\n// {\n//   IKEA: Collection {\n//     items: [\n//        {\n//          id: 100,\n//          product: 'Chair',\n//          manufacturer: 'IKEA',\n//          price: '1490 NOK',\n//        },\n//        {\n//          id: 150,\n//          product: 'Desk',\n//          manufacturer: 'IKEA',\n//          price: '900 NOK',\n//        },\n//      ],\n//   },\n//   'Herman Miller': Collection {\n//     items: [\n//       {\n//         id: 200,\n//         product: 'Chair',\n//         manufacturer: 'Herman Miller',\n//         price: '9990 NOK',\n//       },\n//     ],\n//   },\n// }\n```\n\nIn addition to passing a string key, you may also pass a callback. The callback should return the value you wish to key the group by:\n\n```js\nconst collection = collect([\n  {\n    product: 'Chair',\n    manufacturer: 'IKEA',\n  },\n  {\n    product: 'Desk',\n    manufacturer: 'IKEA',\n  },\n  {\n    product: 'Chair',\n    manufacturer: 'Herman Miller',\n  },\n])\n\nconst grouped = collection.groupBy((item, key) =\u003e item.manufacturer.substring(0, 3))\n\ngrouped.all()\n\n// {\n//   IKE: Collection {\n//     items: [\n//       {\n//         id: 100,\n//         product: 'Chair',\n//         manufacturer: 'IKEA',\n//         price: '1490 NOK',\n//       },\n//       {\n//         id: 150,\n//         product: 'Desk',\n//         manufacturer: 'IKEA',\n//         price: '900 NOK',\n//       },\n//     ],\n//   },\n//   Her: Collection {\n//     items: [\n//       {\n//         id: 200,\n//         product: 'Chair',\n//         manufacturer: 'Herman Miller',\n//         price: '9990 NOK',\n//       },\n//     ],\n//   },\n// }\n```\n\n#### `has()`\n\nThe has method determines if one or more keys exists in the collection:\n\n```js\nconst collection = collect({\n  animal: 'unicorn',\n  ability: 'magical',\n})\n\ncollection.has('ability')\n\n// true\n\ncollection.has(['animal', 'ability'])\n\n// true\n\ncollection.has(['animal', 'ability', 'name'])\n\n// false\n```\n\n#### `implode()`\n\nThe implode method joins the items in a collection. Its arguments depend on the type of items in the collection. If the collection contains arrays or objects, you should pass the key of the attributes you wish to join, and the \"glue\" string you wish to place between the values:\n\n```js\nconst collection = collect([\n  {\n    product: 'Chair',\n    manufacturer: 'IKEA',\n  },\n  {\n    product: 'Desk',\n    manufacturer: 'IKEA',\n  },\n  {\n    product: 'Chair',\n    manufacturer: 'Herman Miller',\n  },\n])\n\ncollection.implode('product', ',')\n\n// Chair, Desk, Chair\n```\n\nIf the collection contains simple strings or numeric values, simply pass the \"glue\" as the only argument to the method:\n\n```js\ncollect([1, 2, 3, 4, 5]).implode('-')\n\n// 1-2-3-4-5\n```\n\n#### `intersect()`\n\nThe intersect method removes any values from the original collection that are not present in the given `array` or `collection`. The resulting collection will preserve the original collection's keys:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\nintersect = collection.intersect([1, 2, 3, 9])\n\nintersect.all()\n\n// [1, 2, 3]\n```\n\n#### `intersectByKeys()`\n\nThe intersectByKeys method removes any keys from the original collection that are not present in the given `array` or collection:\n\n```js\nconst collection = collect({\n  serial: 'UX301',\n  type: 'screen',\n  year: 2009,\n})\n\nconst intersect = collection.intersectByKeys({\n  reference: 'UX404',\n  type: 'tab',\n  year: 2011,\n})\n\nintersect.all()\n\n// { type: 'screen', year: 2009 }\n```\n\n```js\nconst firstCollection = collect([1, 2, 3, 4, 5])\nconst secondCollection = collect([1, 2, 3, 9])\n\nintersect = firstCollection.intersect(secondCollection)\n\nintersect.all()\n\n// [1, 2, 3]\n```\n\n#### `isEmpty()`\n\nThe isEmpty method returns true if the collection is empty; otherwise, false is returned:\n\n```js\ncollect().isEmpty()\n// true\n\ncollect([]).isEmpty()\n// true\n\ncollect({}).isEmpty()\n// true\n```\n\n#### `isNotEmpty()`\n\nThe isNotEmpty method returns true if the collection is not empty; otherwise, false is returned:\n\n```js\ncollect([1, 2, 3]).isNotEmpty()\n//  true\n\ncollect().isNotEmpty()\n// false\n\ncollect([]).isNotEmpty()\n// false\n\ncollect({}).isNotEmpty()\n// false\n```\n\n#### `join()`\n\nThe join method joins the collection's values with a string:\n\n```js\ncollect(['a', 'b', 'c']).join(', ')\n// 'a, b, c'\n\ncollect(['a', 'b', 'c']).join(', ', ', and ')\n// 'a, b, and c'\n\ncollect(['a', 'b']).join(', ', ' and ')\n// 'a and b'\n\ncollect(['a']).join(', ', ' and ')\n// 'a'\n\ncollect([]).join(', ', ' and ')\n// ''\n```\n\n#### `keyBy()`\n\nThe keyBy method keys the collection by the given key. If multiple items have the same key, only the last one will appear in the new collection:\n\n```js\nconst collection = collect([\n  {\n    product: 'Chair',\n    manufacturer: 'IKEA',\n  },\n  {\n    product: 'Desk',\n    manufacturer: 'IKEA',\n  },\n  {\n    product: 'Chair',\n    manufacturer: 'Herman Miller',\n  },\n])\n\nconst keyed = collection.keyBy('manufacturer')\n\nkeyed.all()\n\n// {\n//   IKEA: {\n//     product: 'Desk',\n//     manufacturer: 'IKEA',\n//   },\n//   'Herman Miller': {\n//     product: 'Chair',\n//     manufacturer: 'Herman Miller',\n//   },\n// }\n```\n\nYou may also pass a callback to the method. The callback should return the value to key the collection by:\n\n```js\nconst upperCased = collection.keyBy(item =\u003e item.manufacturer.toUpperCase())\n\nupperCased.all()\n\n// {\n//   IKEA: {\n//     product: 'Desk',\n//     manufacturer: 'IKEA',\n//   },\n//   'HERMAN MILLER': {\n//     product: 'Chair',\n//     manufacturer: 'Herman Miller',\n//   },\n// }\n```\n\n#### `keys()`\n\nThe keys method returns all of the collection's keys:\n\n```js\nconst collection = collect([\n  {\n    club: 'Liverpool',\n    nickname: 'The Reds',\n  },\n])\n\nkeys = collection.keys()\n\n// ['club', 'nickname']\n```\n\n#### `last()`\n\nThe last method returns the last element in the collection that passes a given truth test:\n\n```js\nconst collection = collect([1, 2, 3])\n\nconst last = collection.last(item =\u003e item \u003e 1)\n\n// 3\n```\n\nYou may also call the last method with no arguments to get the last element in the collection. If the collection is empty, `null` is returned:\n\n```js\ncollect([1, 2, 3, 4]).last()\n\n// 4\n```\n\n#### `macro()`\n\nThe macro method lets you register custom methods\n\n```js\ncollect().macro('uppercase', function () {\n  return this.map(item =\u003e item.toUpperCase())\n})\n\nconst collection = collect(['a', 'b', 'c'])\n\ncollection.uppercase()\n\ncollection.all()\n\n// ['A', 'B', 'C']\n```\n\n\u003e Note that the `macro` method returns `undefined`, and therefore it is not possible to use it within a chain of methods.\n\n#### `make()`\n\nThe make method creates a new collection instance.\n\n\u003e This is only added to adhere to the Laravel collection API, when using Collect.js it's recommended to use `collect()` directly when creating a new collection.\n\n#### `map()`\n\nThe map method iterates through the collection and passes each value to the given callback. The callback is free to modify the item and return it, thus forming a new collection of modified items:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\nconst multiplied = collection.map(item =\u003e item * 2)\n\nmultiplied.all()\n\n// [2, 4, 6, 8, 10]\n```\n\n\u003e Like most other collection methods, `map` returns a new collection instance; it does not modify the collection it is called on. If you want to transform the original collection, use the `transform` method.\n\n#### `mapInto()`\n\nThe mapInto method iterates through the collection and instantiates the given class with each element as a constructor:\n\n```js\nconst Player = function (name) {\n  this.name = name\n}\n\nconst collection = collect([\n  'Roberto Firmino',\n  'Sadio Mané',\n])\n\nconst players = collection.mapInto(Player)\n\nplayers.all()\n\n// [\n//   Player { name: 'Roberto Firmino' },\n//   Player { name: 'Sadio Mané' },\n// ]\n```\n\n#### `mapSpread()`\n\nThe mapSpread method iterates over the collection's items, passing each nested item value into the given callback.\nThe callback is free to modify the item and return it, thus forming a new collection of modified items:\n\n```js\nconst collection = collect([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n\nconst chunks = collection.chunk(2)\n\nconst sequence = chunks.mapSpread((even, odd) =\u003e even + odd)\n\nsequence.all()\n\n// [1, 5, 9, 13, 17]\n```\n\n#### `mapToDictionary()`\n\nRun a dictionary map over the items.\nThe callback should return an associative array with a single key/value pair.\n\n```js\nconst collection = collect([\n  { id: 1, name: 'a' },\n  { id: 2, name: 'b' },\n  { id: 3, name: 'c' },\n  { id: 4, name: 'b' },\n])\n\nconst groups = collection.mapToDictionary(item =\u003e [item.name, item.id])\n\ngroups.all()\n\n// {\n//   a: [1],\n//   b: [2, 4],\n//   c: [3],\n// }\n```\n\n#### `mapToGroups()`\n\nThe mapToGroups method iterates through the collection and passes each value to the given callback:\n\n```js\nconst collection = collect([\n  { id: 1, name: 'A' },\n  { id: 2, name: 'B' },\n  { id: 3, name: 'C' },\n  { id: 4, name: 'B' },\n])\n\nconst groups = collection.mapToGroups((item, key) =\u003e [item.name, item.id])\n\n// {\n//   A: [1],\n//   B: [2, 4],\n//   C: [3],\n// }\n```\n\n#### `mapWithKeys()`\n\nThe mapWithKeys method iterates through the collection and passes each value to the given callback. The callback should return an array where the first element represents the key and the second element represents the value pair:\n\n```js\nconst collection = collect([\n  {\n    name: 'John',\n    department: 'Sales',\n    email: 'john@example.com',\n  },\n  {\n    name: 'Jane',\n    department: 'Marketing',\n    email: 'jane@example.com',\n  },\n])\n\nconst keyed = collection.mapWithKeys(item =\u003e [item.email, item.name])\n\nkeyed.all()\n\n// {\n//   'john@example.com': 'John',\n//   'jane@example.com': 'Jane',\n// }\n```\n\n#### `max()`\n\nThe max method returns the maximum value of a given key:\n\n```js\nconst collection = collect([\n  {\n    value: 10,\n  },\n  {\n    value: -13,\n  },\n  {\n    value: 12,\n  },\n  {\n    unicorn: false,\n  },\n])\n\nconst max = collection.max('value')\n\n// 12\n```\n\n```js\ncollect([-1, -2345, 12, 11, 3]).max()\n\n// 12\n```\n\n#### `median()`\n\nThe median method returns the median value of a given key:\n\n```js\ncollect([1, 3, 3, 6, 7, 8, 9]).median()\n\n// 6\n```\n\n```js\ncollect([\n  {\n    foo: 1,\n  },\n  {\n    foo: 1,\n  },\n  {\n    foo: 2,\n  },\n  {\n    foo: 4,\n  },\n]).median('foo')\n\n// 1.5\n```\n\n#### `merge()`\n\nThe merge method merges the given object into the original collection. If a key in the given object matches a key in the original collection, the given objects value will overwrite the value in the original collection:\n\n```js\nconst collection = collect({\n  id: 1,\n  price: 29,\n})\n\nconst merged = collection.merge({\n  price: 400,\n  discount: false,\n})\n\nmerged.all()\n\n// { id: 1, price: 400, discount: false }\n```\n\nIf our collection is an array, the values will be appended to the end of the collection:\n\n```js\nconst collection = collect(['Unicorn', 'Rainbow'])\n\nconst merged = collection.merge(['Sunshine', 'Rainbow'])\n\nmerged.all()\n\n// ['Unicorn', 'Rainbow', 'Sunshine', 'Rainbow']\n```\n\n#### `mergeRecursive()`\n\nThe mergeRecursive method merges the given array or collection recursively with the original collection. If a string key in the given items matches a string key in the original collection, then the values for these keys are merged together into an array, and this is done recursively:\n\n```js\nconst collection = collect({\n  product_id: 1,\n  price: 100,\n})\n\nconst merged = collection.mergeRecursive({\n  product_id: 2,\n  price: 200,\n  discount: false,\n})\n\nmerged.all()\n\n// {\n//   product_id: [1, 2],\n//   price: [100, 200],\n//   discount: false,\n// }\n```\n\n#### `min()`\n\nThe min method returns the minimum value of a given key:\n\n```js\nconst collection = collect([\n  {\n    worth: 100,\n  },\n  {\n    worth: 900,\n  },\n  {\n    worth: 79,\n  },\n])\n\ncollection.min('worth')\n\n// 79\n```\n\n```js\ncollect([1, 2, 3, 4, 5]).min()\n\n// 1\n```\n\n#### `mode()`\n\nThe mode method returns the mode value of a given key:\n\n```js\ncollect([1, 3, 3, 6, 7, 8, 9]).mode()\n\n// [3]\n```\n\n```js\ncollect([\n  {\n    foo: 1,\n  },\n  {\n    foo: 1,\n  },\n  {\n    foo: 2,\n  },\n  {\n    foo: 4,\n  },\n]).mode('foo')\n\n// [1]\n```\n\n#### `nth()`\n\nThe nth method creates a new collection consisting of every n-th element:\n\n```js\nconst collection = collect(['a', 'b', 'c', 'd', 'e', 'f'])\n\nconst nth = collection.nth(4)\n\nnth.all()\n\n// ['a', 'e']\n```\n\n#### `only()`\n\nThe only method returns the items in the collection with the specified keys:\n\n```js\nconst collection = collect({\n  id: 12,\n  name: 'John Doe',\n  email: 'john@doe.com',\n  active: true,\n})\n\nconst filtered = collection.only(['name', 'email'])\n\nfiltered.all()\n\n// { name: 'John Doe', email: 'john@doe.com' }\n```\n\n```js\ncollect([1, 2, 3, 4])\n  .only([2, 12])\n  .all()\n\n// [2]\n```\n\n\u003e For the inverse of `only`, see the `except` method.\n\n#### `pad()`\n\nThe pad method will fill the array with the given value until the array reaches the specified size. This method\nbehaves like the [array_pad](https://secure.php.net/manual/en/function.array-pad.php) PHP function.\n\nTo pad to the left, you should specify a negative size. No padding will take place if the absolute value of the given size is less than or equal to the length of the array:\n\n```js\nconst collection = collect(['A', 'B', 'C'])\n\nlet filtered = collection.pad(5, 0)\n\nfiltered.all()\n\n// ['A', 'B', 'C', 0, 0]\n\nfiltered = collection.pad(-5, 0)\n\nfiltered.all()\n\n// [0, 0, 'A', 'B', 'C']\n```\n\n#### `partition()`\n\nThe partition method may be combined with destructuring to separate elements that pass a given truth test from those that do not:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5, 6])\n\nconst [underThree, overThree] = collection.partition(i =\u003e i \u003c 3)\n```\n\n#### `pipe()`\n\nThe pipe method passes the collection to the given callback and returns the result:\n\n```js\nconst collection = collect([1, 2, 3])\n\nconst piped = collection.pipe(items =\u003e items.sum())\n\n// 6\n```\n\n#### `pluck()`\n\nThe pluck method retrieves all of the values for a given key:\n\n```js\nconst collection = collect([\n  {\n    id: 78,\n    name: 'Aeron',\n  },\n  {\n    id: 79,\n    name: 'Embody',\n  },\n])\n\nconst plucked = collection.pluck('name')\n\nplucked.all()\n\n// ['Aeron', 'Embody']\n```\n\nYou may also specify how you wish the resulting collection to be keyed:\n\n```js\nconst collection = collect([\n  {\n    id: 78,\n    name: 'Aeron',\n  },\n  {\n    id: 79,\n    name: 'Embody',\n  },\n])\n\nconst plucked = collection.pluck('name', 'id')\n\nplucked.all()\n\n// {\n//   78: 'Aeron',\n//   79: 'Embody',\n// }\n```\n\nYou can use \"dot notation\" to access nested values\n\n```js\nconst collection = collect([\n  {\n    name: 'John',\n    roles: [\n      {\n        name: 'Editor',\n      },\n      {\n        name: 'Admin',\n      },\n    ],\n  },\n])\n\nconst plucked = collection.pluck('roles.0.name')\n\nplucked.all()\n\n// ['Editor']\n```\n\n\"Dot notation\" supports \"wildcard\"\n\n```js\nconst collection = collect([\n  {\n    name: 'John',\n    roles: [\n      {\n        name: 'Editor',\n      },\n      {\n        name: 'Admin',\n      },\n    ],\n  },\n])\n\nconst plucked = collection.pluck('roles.*.name')\n\nplucked.all()\n\n// [\n//   [\n//     'Editor',\n//     'Admin',\n//   ],\n// ]\n```\n\n#### `pop()`\n\nThe pop method removes and returns the last item from the collection:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\ncollection.pop()\n\n// 5\n\ncollection.all()\n\n// =\u003e [1, 2, 3, 4]\n```\n\nYou may provide number of items to pop. This will return the popped items in a new collection:\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\ncollection.pop(2).all()\n\n// [4, 5]\n\ncollection.all()\n\n// =\u003e [1, 2, 3]\n```\n\n#### `prepend()`\n\nThe prepend method adds an item to the beginning of the collection:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\ncollection.prepend(0)\n\ncollection.all()\n\n// [0, 1, 2, 3, 4, 5]\n```\n\nYou may also pass a second argument to set the key of the prepended item:\n\n\u003e Pro tip: Order of properties in objects is not guaranteed in JavaScript; When calling prepend with a key, the Collection uses the underlying `put` method behind the scenes. This is only supported so that collect.js have the same api as Laravel Collections.\n\n```js\nconst collection = collect({\n  product: 'iPhone 6s',\n})\n\ncollection.prepend('Apple', 'brand')\n\ncollection.all()\n\n// {\n//   brand: 'Apple',\n//   product: 'iPhone 6s',\n// }\n```\n\n#### `pull()`\n\nThe pull method removes and returns an item from the collection by its key:\n\n```js\nconst collection = collect({\n  firstname: 'Michael',\n  lastname: 'Cera',\n})\n\ncollection.pull('lastname')\n\n// Cera\n\ncollection.all()\n\n// { firstname: 'Michael' }\n```\n\n#### `push()`\n\nThe push method appends an item to the end of the collection:\n\n```js\nconst collection = collect([1, 2, 3, 4])\n\ncollection.push(5)\n\ncollection.all()\n\n// [1, 2, 3, 4, 5]\n```\n\n#### `put()`\n\nThe put method sets the given key and value in the collection:\n\n```js\nconst collection = collect(['JavaScript', 'Python'])\n\ncollection.put('Ruby')\n\ncollection.all()\n\n// ['JavaScript', 'Python', 'Ruby']\n```\n\n#### `random()`\n\nThe random method returns a random item from the collection:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\ncollection.random()\n\n// 4 (retrieved randomly)\n```\n\nYou may optionally pass an integer to random to specify how many items you would like to randomly retrieve. A collection of items is always returned when explicitly passing the number of items you wish to receive:\n\n```js\nconst threeRandom = collection.random(3)\n\n// Collection { items: [ 5, 3, 4 ] } (retrieved randomly)\n\nconst oneRandom = collection.random(1)\n\n// Collection { items: [ 3 ] } (retrieved randomly)\n\noneRandom.all()\n\n// [3]\n```\n\n#### `reduce()`\n\nThe reduce method reduces the collection to a single value, passing the result of each iteration into the subsequent iteration:\n\n```js\nconst collection = collect([1, 2, 3])\n\nconst total = collection.reduce((carry, item) =\u003e carry + item)\n\n// 6\n```\n\nThe value for `carry` on the first iteration is null; however, you may specify its initial value by passing a second argument to reduce:\n\n```js\nconst total = collection.reduce((carry, item) =\u003e carry + item, 4)\n\n// 10\n```\n\n#### `reject()`\n\nThe reject method filters the collection using the given callback. The callback should return true if the item should be removed from the resulting collection:\n\n```js\nconst collection = collect([1, 2, 3, 4])\n\nconst filtered = collection.reject(value =\u003e value \u003e 2)\n\n// [1, 2]\n```\n\n\u003e For the inverse of the `reject` method, see the `filter` method.\n\n#### `replace()`\n\nThe replace method behaves similarly to merge; however, in addition to overwriting matching items with string keys, the replace method will also overwrite items in the collection that have matching numeric keys:\n\n```js\nconst collection = collect({\n  name: 'Bob',\n})\n\nconst replaced = collection.replace({\n  name: 'John',\n  number: 45,\n})\n\nreplaced.all()\n\n// {\n//   name: 'John',\n//   number: 45,\n// }\n```\n\n#### `replaceRecursive()`\n\nThis method works like replace, but it will recurse into arrays and apply the same replacement process to the inner values:\n\n```js\nconst collection = collect([\n  'Matip',\n  'van Dijk',\n  [\n    'Mané',\n    'Firmino',\n    'Salah',\n  ],\n])\n\nconst replaced = collection.replaceRecursive({\n  0: 'Gomez',\n  2: { 1: 'Origi' },\n})\n\nreplaced.all()\n\n// {\n//   0: 'Gomez',\n//   1: 'van Dijk',\n//   2: { 0: 'Mané', 1: 'Origi', 2: 'Salah' },\n// }\n```\n\n#### `reverse()`\n\nThe reverse method reverses the order of the collection's items:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\nconst reversed = collection.reverse()\n\nreversed.all()\n\n// [5, 4, 3, 2, 1]\n```\n\n#### `search()`\n\nThe search method searches the collection for the given value and returns its key if found. If the item is not found, false is returned.\n\n```js\nconst collection = collect([2, 4, 6, 8])\n\ncollection.search(4)\n\n// 1\n```\n\nThe search is done using a \"loose\" comparison, meaning a string with an integer value will be considered equal to an integer of the same value. To use strict comparison, pass true as the second argument to the method:\n\n```js\ncollection.search('4', true)\n\n// false\n```\n\nAlternatively, you may pass in your own callback to search for the first item that passes your truth test:\n\n```js\ncollection.search((item, key) =\u003e item \u003e 5)\n\n// 2\n```\n\n#### `shift()`\n\nThe shift method removes and returns the first item from the collection:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\ncollection.shift()\n\n// 1\n\ncollection.all()\n\n// [2, 3, 4, 5]\n```\n\nYou may provide number of items to shift. This will return the shifted items in a new collection:\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\ncollection.shift(2).all()\n\n// [1, 2]\n\ncollection.all()\n\n// =\u003e [3, 4, 5]\n```\n\n#### `shuffle()`\n\nThe shuffle method randomly shuffles the items in the collection:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\nconst shuffled = collection.shuffle()\n\nshuffled.all()\n\n// [3, 5, 1, 2, 4] (generated randomly)\n```\n\n#### `skip()`\n\nThe skip method returns a new collection, without the first given amount of items:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5, 6])\n\ncollection.skip(4).all()\n\n// [5, 6]\n```\n\n```js\nconst collection = collect({\n  first: 'first',\n  second: 'second',\n  third: 'third',\n  fourth: 'fourth',\n  fifth: 'fifth',\n})\n\ncollection.skip(4).all()\n\n// { fifth: 'fifth' }\n```\n\n\n#### `skipUntil()`\n\nThe `skipUntil` method skips items until the given callback returns `true` and then returns the remaining items in the collection:\n\n```js\nconst collection = collect([1, 2, 3, 4])\n\nconst subset = collection.skipUntil(item =\u003e item \u003e= 3)\n\nsubset.all()\n\n// [3, 4]\n```\n\nYou may also pass a simple value to the `skipUntil` method to skip all items until the given value is found:\n\n```js\nconst collection = collect([1, 2, 3, 4])\n\nconst subset = collection.skipUntil(3)\n\nsubset.all()\n\n// [3, 4]\n```\n\n\n#### `skipWhile()`\n\nThe `skipWhile` method skips items while the given callback returns `true` and then returns the remaining items in the collection:\n\n```js\nconst collection = collect([1, 2, 3, 4])\n\nconst subset = collection.skipWhile(item =\u003e item \u003c= 3)\n\nsubset.all()\n\n// [4]\n```\n\n\u003e If the callback never returns true, the skipWhile method will return an empty collection.\n\nYou may also pass a simple value to the `skipWhile`:\n\n```js\nconst collection = collect([1, 1, 2, 2, 3, 3, 4, 4])\n\nconst subset = collection.skipWhile(1)\n\nsubset.all()\n\n// [2, 2, 3, 3, 4, 4]\n```\n\n\n#### `slice()`\n\nThe slice method returns a slice of the collection starting at the given index:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])\n\nconst slice = collection.slice(4)\n\nslice.all()\n\n// [5, 6, 7, 8, 9, 10]\n```\n\nIf you would like to limit the size of the returned slice, pass the desired size as the second argument to the method:\n\n```js\nconst slice = collection.slice(4, 2)\n\nslice.all()\n\n// [5, 6]\n```\n\n#### `sole()`\n\nThe sole method returns the first element in the collection that passes a given truth test, but only if the truth test matches exactly one element:\n\n```js\ncollect([1, 2, 3, 4]).sole(item =\u003e item === 1)\n\n// 1\n```\n\nIf there are no elements in the collection that should be returned by the sole method, then an error will be thrown:\n\n```js\ncollect([1, 2, 3, 4]).sole(item =\u003e item \u003e 4)\n\n// Error ('Item not found.') is thrown.\n```\n\nIf there are multiple elements in the collection that should be returned by the sole method, then an error will be thrown:\n\n```js\ncollect([1, 2, 3, 4]).sole()\n\n// Error ('Multiple items found.') is thrown.\n```\n\nLike the firstOrFail method, you may also pass an attribute, operator, and value:\n\n```js\nconst collection = collect([\n  { product: 'Desk', price: 200, discounted: true },\n  { product: 'Chair', price: 100, discounted: true },\n  { product: 'Bookcase', price: 150, discounted: true },\n  { product: 'Door', price: 100 },\n])\n\ncollection.sole('product', '=', 'Desk')\n\n// { product: 'Desk', price: 200, discounted: true }\n```\n\n\n#### `some()`\n\nAlias for the [contains](#contains) method.\n\n#### `sort()`\n\nThe sort method sorts the collection:\n\n```js\nconst collection = collect([5, 3, 1, 2, 4])\n\nconst sorted = collection.sort()\n\nsorted.all()\n\n// [1, 2, 3, 4, 5]\n```\n\n\u003e If your sorting needs are more advanced, you may pass a callback to sort with your own algorithm.\n\n```js\nconst collection = collect([5, 3, 1, 2, 4])\n\nconst sorted = collection.sort((a, b) =\u003e b - a)\n\nsorted.all()\n\n// [5, 4, 3, 2, 1]\n```\n\n\u003e If you need to sort a collection of nested arrays or objects, see the `sortBy` and `sortByDesc` methods.\n\n#### `sortBy()`\n\nThe sortBy method sorts the collection by the given key. The sorted collection keeps the original array keys, so in this example we'll use the values method to reset the keys to consecutively numbered indexes:\n\n```js\nconst collection = collect([\n  { name: 'Desk', price: 200 },\n  { name: 'Chair', price: 100 },\n  { name: 'Bookcase', price: 150 },\n])\n\nconst sorted = collection.sortBy('price')\n\nsorted.all()\n\n// [\n//   { name: 'Chair', price: 100 },\n//   { name: 'Bookcase', price: 150 },\n//   { name: 'Desk', price: 200 },\n// ]\n```\n\nYou can use dot notation to sort by nested values\n```js\nconst collection = collect([\n  {\n    name: 'Desk',\n    price: 200,\n    manufacturer: {\n      name: 'IKEA',\n    },\n  },\n  {\n    name: 'Chair',\n    price: 100,\n    manufacturer: {\n      name: 'Herman Miller',\n    },\n  },\n  {\n    name: 'Bookcase',\n    price: 150,\n    manufacturer: {\n      name: 'IKEA',\n    },\n  },\n])\n\nconst sorted = collection.sortBy('manufacturer.name')\n\nsorted.all()\n\n// [\n//   {\n//     name: 'Chair',\n//     price: 100,\n//     manufacturer: {\n//       name: 'Herman Miller',\n//     },\n//   },\n//   {\n//     name: 'Desk',\n//     price: 200,\n//     manufacturer: {\n//       name: 'IKEA',\n//     },\n//   },\n//   {\n//     name: 'Bookcase',\n//     price: 150,\n//     manufacturer: {\n//       name: 'IKEA',\n//     },\n//   },\n// ]\n```\n\nYou can also pass your own callback to determine how to sort the collection values:\n\n```js\nconst collection = collect([\n  { name: 'Desk', colors: ['Black', 'Mahogany'] },\n  { name: 'Chair', colors: ['Black'] },\n  { name: 'Bookcase', colors: ['Red', 'Beige', 'Brown'] },\n])\n\nconst sorted = collection.sortBy((product, key) =\u003e product.colors.length)\n\nsorted.all()\n\n// [\n//   { name: 'Chair', colors: ['Black'] },\n//   { name: 'Desk', colors: ['Black', 'Mahogany'] },\n//   { name: 'Bookcase', colors: ['Red', 'Beige', 'Brown'] },\n// ]\n```\n\n#### `sortByDesc()`\n\nThis method has the same signature as the `sortBy` method, but will sort the collection in the opposite order.\n\n#### `sortDesc()`\n\nThis method will sort the collection in the opposite order as the `sort` method.\n\n```js\nconst collection = collect([1, 3, 5, 2, 4])\n\nconst sorted = collection.sortDesc()\n\nsorted.all()\n\n// [5, 4, 3, 2, 1]\n```\n\nUnlike `sort`, you may not pass a callback to `sortDesc`. If you wish to use a callback, you should use `sort` and invert your comparison.\n\n#### `sortKeys()`\n\nThe sortKeys method sorts the collection by the keys of the underlying associative array:\n\n```js\nconst collection = collect({\n  id: 10,\n  first: 'Sadio',\n  last: 'Mané',\n})\n\nconst sorted = collection.sortKeys()\n\nsorted.all()\n\n// {\n//   first: 'Sadio',\n//   id: 10,\n//   last: 'Mané',\n// }\n```\n\n#### `sortKeysDesc()`\nThis method has the same signature as the [sortKeys](#sortkeys) method, but will sort the collection in the opposite order.\n\n#### `splice()`\n\nThe splice method removes and returns a slice of items starting at the specified index:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\nconst chunk = collection.splice(2)\n\nchunk.all()\n\n// [3, 4, 5]\n\ncollection.all()\n\n// [1, 2]\n```\n\nYou may pass a second argument to limit the size of the resulting chunk:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\nconst chunk = collection.splice(2, 1)\n\nchunk.all()\n\n// [3]\n\ncollection.all()\n\n// [1, 2, 4, 5]\n```\n\nIn addition, you can pass a third argument containing the new items to replace the items removed from the collection:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\nconst chunk = collection.splice(2, 1, [10, 11])\n\nchunk.all()\n\n// [3]\n\ncollection.all()\n\n// [1, 2, 10, 11, 4, 5]\n```\n\n#### `split()`\n\nThe split method breaks a collection into the given number of groups:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\nconst groups = collection.split(3)\n\n// [[1, 2], [3, 4], [5]]\n```\n\n#### `sum()`\n\nThe sum method returns the sum of all items in the collection:\n\n```js\ncollect([1, 2, 3]).sum()\n\n// 6\n```\n\nIf the collection contains nested arrays or objects, you should pass a key to use for determining which values to sum:\n\n```js\nconst collection = collect([\n  { name: 'My story', pages: 176 },\n  { name: 'Fantastic Beasts and Where to Find Them', pages: 1096 },\n])\n\ncollection.sum('pages')\n\n// 1272\n```\n\nIn addition, you may pass your own callback to determine which values of the collection to sum:\n\n```js\nconst collection = collect([\n  { name: 'Desk', colors: ['Black', 'Mahogany'] },\n  { name: 'Chair', colors: ['Black'] },\n  { name: 'Bookcase', colors: ['Red', 'Beige', 'Brown'] },\n])\n\nconst total = collection.sum(product =\u003e product.colors.length)\n\n// 6\n```\n\n#### `take()`\n\nThe take method returns a new collection with the specified number of items:\nYou may also pass a negative integer to take the specified amount of items from the end of the collection:\n\n```js\nconst collection = collect([0, 1, 2, 3, 4, 5])\n\nconst chunk = collection.take(3)\n\nchunk.all()\n\n// [0, 1, 2]\n```\n\n#### `takeUntil()`\n\nThe `takeUntil` method returns items in the collection until the given callback returns `true`:\n\n```js\nconst collection = collect([1, 2, 3, 4])\n\nconst subset = collection.takeUntil(item =\u003e item \u003e= 3)\n\nsubset.all()\n\n// [1, 2]\n```\n\n\u003e If the given value is not found or the callback never returns `true`, the `takeUntil` method will return all items in the collection.\n\nYou may also pass a simple value to the `takeUntil` method to get the items until the given value is found:\n\n```js\nconst collection = collect([1, 2, 3, 4])\n\nconst subset = collection.takeUntil(3)\n\nsubset.all()\n\n// [1, 2]\n```\n\n\n#### `takeWhile()`\n\nThe `takeWhile` method returns items in the collection until the given callback returns `false`:\n\n```js\nconst collection = collect([1, 2, 3, 4])\n\nconst subset = collection.takeWhile(item =\u003e item \u003c 3)\n\nsubset.all()\n\n// [1, 2]\n```\n\n\u003e If the callback never returns `false`, the `takeWhile` method will return all items in the collection.\n\n\n#### `tap()`\n\nThe tap method passes the collection to the given callback, allowing you to \"tap\" into the collection at a specific point and do something with the items while not affecting the collection itself:\n\n```js\ncollect([2, 4, 3, 1, 5])\n  .sort()\n  .tap((collection) =\u003e {\n    console.log(collection.all())\n\n    // [1, 2, 3, 4, 5]\n  })\n  .shift()\n\n// 1\n```\n\n#### `times()`\n\nThe times method creates a new collection by invoking the callback a given amount of times:\n\n```js\nconst collection = collect().times(10, number =\u003e number * 9)\n\ncollection.all()\n\n// [9, 18, 27, 36, 45, 54, 63, 72, 81, 90]\n```\n\n#### `toArray()`\n\nThe toArray method converts the collection into a plain array.\nIf the collection is an object, an array containing the values will be returned.\n\n```js\nconst collection = collect([1, 2, 3, 'b', 'c'])\n\ncollection.toArray()\n\n// [1, 2, 3, 'b', 'c']\n```\n\n```js\nconst collection = collect({\n  name: 'Elon Musk',\n  companies: ['Tesla', 'Space X', 'SolarCity'],\n})\n\ncollection.toArray()\n\n// ['Elon Musk', ['Tesla', 'Space X', 'SolarCity']]\n```\n\n#### `toJson()`\n\nThe toJson method converts the collection into JSON string:\n\n```js\nconst collection = collect({\n  id: 384,\n  name: 'Rayquaza',\n  gender: 'NA',\n})\n\nconst json = collection.toJson()\n\n// {\"id\": 384, \"name\": \"Rayquaza\", \"gender\": \"NA\"}\n```\n\n#### `transform()`\n\nThe transform method iterates over the collection and calls the given callback with each item in the collection. The items in the collection will be replaced by the values returned by the callback:\n\n```js\nconst collection = collect([1, 2, 3, 4, 5])\n\ncollection.transform((item, key) =\u003e item * 2)\n\ncollection.all()\n\n// [2, 4, 6, 8, 10]\n```\n\n\u003e Unlike most other collection methods, `transform` modifies the collection itself. If you wish to create a new collection instead, use the `map` method.\n\n#### `undot()`\n\nThe `undot` method expands a single-dimensional collection that uses \"dot\" notation into a multi-dimensional collection:\n\n```js\nconst person = collect({\n  'name.first_name': 'Marie',\n  'name.last_name': 'Valentine',\n  'address.line_1': '2992 Eagle Drive',\n  'address.line_2': '',\n  'address.suburb': 'Detroit',\n  'address.state': 'MI',\n  'address.postcode': '48219',\n})\n\nconst undotted = person.undot()\n\nconst all = undotted.all()\n\n// {\n//   name: {\n//       first_name: 'Marie',\n//       last_name: 'Valentine',\n//   },\n//   address: {\n//       line_1: '2992 Eagle Drive',\n//       line_2: '',\n//       suburb: 'Detroit',\n//       state: 'MI',\n//       postcode: '48219',\n//   },\n// }\n```\n\n\n#### `union()`\n\nThe union method adds the given array to the collection. If the given array contains keys that are already in the original collection, the original collection's values will be preferred:\n\n```js\nconst collection = collect({\n  a: 'A',\n  b: 'B',\n})\n\nconst union = collection.union({\n  a: 'AAA',\n  c: 'CCC',\n  b: 'BBB',\n})\n\nunion.all()\n\n// {\n//   a: 'A',\n//   b: 'B',\n//   c: 'CCC',\n// }\n```\n\n#### `unique()`\n\nThe unique method returns all of the unique items in the collection:\n\n```js\nconst collection = collect([1, 1, 1, 2, 3, 3])\n\nconst unique = collection.unique()\n\nunique.all()\n\n// [1, 2, 3]\n```\n\nWhen dealing with an array of objects, you may specify the key used to determine uniqueness:\n\n```js\nconst collection = collect([\n  { name: 'iPhone 6', brand: 'Apple', type: 'phone' },\n  { name: 'iPhone 5', brand: 'Apple', type: 'phone' },\n  { name: 'Apple Watch', brand: 'Apple', type: 'watch' },\n  { name: 'Galaxy S6', brand: 'Samsung', type: 'phone' },\n  { name: 'Galaxy Gear', brand: 'Samsung', type: 'watch' },\n])\n\nconst unique = collection.unique('brand')\n\nunique.all()\n\n// [\n//   { name: 'iPhone 6', brand: 'Apple', type: 'phone' },\n//   { name: 'Galaxy S6', brand: 'Samsung', type: 'phone' },\n// ]\n```\n\nYou may also pass your own callback to determine item uniqueness:\n\n```js\nconst collection = collect([\n  { name: 'iPhone 6', brand: 'Apple', type: 'phone' },\n  { name: 'iPhone 5', brand: 'Apple', type: 'phone' },\n  { name: 'Apple Watch', brand: 'Apple', type: 'watch' },\n  { name: 'Galaxy S6', brand: 'Samsung', type: 'phone' },\n  { name: 'Galaxy Gear', brand: 'Samsung', type: 'watch' },\n])\n\nconst unique = collection.unique(item =\u003e item.brand + item.type)\n\nunique.all()\n\n// [\n//   { name: 'iPhone 6', brand: 'Apple', type: 'phone' },\n//   { name: 'Apple Watch', brand: 'Apple', type: 'watch' },\n//   { name: 'Galaxy S6', brand: 'Samsung', type: 'phone' },\n//   { name: 'Galaxy Gear', brand: 'Samsung', type: 'watch' },\n// ]\n```\n\n#### `unless()`\n\nThe unless method will execute the given callback when the first argument given to the method evaluates to false:\n\n```js\nconst collection = collect([1, 2, 3])\n\ncollection.unless(false, items =\u003e items.push(4))\n\ncollection.all()\n\n// [1, 2, 3, 4]\n```\n\n#### `unlessEmpty()`\n\nAlias for the [`whenNotEmpty()`](#whenNotEmpty) method\n\n#### `unlessNotEmpty()`\n\nAlias for the [`whenEmpty()`](#whenEmpty) method\n\n#### `unwrap()`\n\nThe unwrap method will unwrap the given collection:\n\n```js\nconst collection = collect([1, 2, 3])\n\ncollect().unwrap(collection)\n\n// [1, 2, 3]\n```\n\n#### `values()`\n\nThe values method returns a new collection with the keys reset to consecutive integers:\n\n```js\nconst collection = collect({\n  a: 'xoxo',\n  b: 'abab',\n  c: '1337',\n  1337: 12,\n})\n\nconst values = collection.values()\n\nvalues.all()\n\n// [12, 'xoxo', 'abab', '1337']\n```\n\n#### `when()`\n\nThe when method will execute the given callback when the first argument given to the method evaluates to true:\n\n```js\nconst collection = collect([1, 2, 3])\n\ncollection.when(true, items =\u003e items.push(4))\n\ncollection.all()\n\n// [1, 2, 3, 4]\n```\n\n#### `whenEmpty()`\n\nThe `whenEmpty` method will execute the given callback when the collection is empty:\n\n```js\nconst collection = collect([])\n\ncollection.whenEmpty(c =\u003e c.push('Mohamed Salah'))\n\ncollection.all()\n\n// ['Mohamed Salah']\n```\n\n```js\nconst collection = collect(['Sadio Mané'])\n\ncollection.whenEmpty(\n  c =\u003e c.push('Mohamed Salah'),\n  c =\u003e c.push('Xherdan Shaqiri'),\n)\n\ncollection.all()\n\n// [\n//   'Sadio Mané',\n//   'Xherdan Shaqiri',\n// ];\n```\n\n#### `whenNotEmpty()`\n\nThe `whenNotEmpty` method will execute the given callback when the collection is not empty:\n\n```js\nconst collection = collect(['Sadio Mané'])\n\ncollection.whenNotEmpty(c =\u003e c.push('Mohamed Salah'))\n\ncollection.all()\n\n// [\n//   'Sadio Mané',\n//   'Mohamed Salah',\n// ]\n```\n\n```js\nconst collection = collect(['Sadio Mané'])\n\ncollection.whenNotEmpty(\n  c =\u003e c.push('Mohamed Salah'),\n  c =\u003e c.push('Xherdan Shaqiri'),\n)\n\ncollection.all()\n\n// [\n//   'Sadio Mané',\n//   'Mohamed Salah',\n// ];\n```\n\n#### `where()`\n\nThe where method filters the collection by a given key / value pair:\n\n```js\nconst collection = collect([\n  { product: 'Desk', price: 200, discounted: true },\n  { product: 'Chair', price: 100, discounted: true },\n  { product: 'Bookcase', price: 150, discounted: true },\n  { product: 'Door', price: 100 },\n])\n\nconst filtered = collection.where('price', 100)\n\nfiltered.all()\n\n// [\n//   { product: 'Chair', price: 100 },\n//   { product: 'Door', price: 100 },\n// ]\n\nconst discounted = collection.where('discounted')\n\ndiscounted.all()\n\n// [\n//  { product: 'Desk', price: 200, discounted: true },\n//  { product: 'Chair', price: 100, discounted: true },\n//  { product: 'Bookcase', price: 150, discounted: true },\n// ]\n\nconst notDiscounted = collection.where('discounted', false)\n\ndiscounted.all()\n\n// [\n//  { product: 'Door', price: 100 },\n// ]\n```\n\n\u003e When working with nested objects `where()` method allows dot notated keys. E.g. `where('product.category', 'office-supplies')`\n\u003e The where method also allows for custom comparisons:\n\n**Non-identity / strict inequality `(!==)`**\n\n```js\nconst filtered = collection.where('price', '!==', 100)\n\nfiltered.all()\n\n// [\n//   { product: 'Desk', price: 200 },\n//   { product: 'Bookcase', price: 150 },\n// ]\n```\n\n**Less than operator `(\u003c)`**\n\n```js\nconst filtered = collection.where('price', '\u003c', 100)\n\nfiltered.all()\n\n// []\n```\n\n**Less than or equal operator `(\u003c=)`**\n\n```js\nconst filtered = collection.where('price', '\u003c=', 100)\n\nfiltered.all()\n\n// [\n//   { product: 'Chair', price: 100 },\n//   { product: 'Door', price: 100 },\n// ]\n```\n\n**Greater than operator `(\u003e)`**\n\n```js\nconst filtered = collection.where('price', '\u003e', 100)\n\nfiltered.all()\n\n// [\n//   { product: 'Desk', price: 200} ,\n//   { product: 'Bookcase', price: 150 },\n// ]\n```\n\n**Greater than or equal operator `(\u003e=)`**\n\n```js\nconst filtered = collection.where('price', '\u003e=', 150)\n\nfiltered.all()\n\n// [\n//   { product: 'Desk', price: 200} ,\n//   { product: 'Bookcase', price: 150 },\n// ]\n```\n\n#### `whereBetween()`\n\nThe whereBetween method filters the collection within a given range:\n\n```js\nconst collection = collect([\n  { product: 'Desk', price: 200 },\n  { product: 'Chair', price: 80 },\n  { product: 'Bookcase', price: 150 },\n  { product: 'Pencil', price: 30 },\n  { product: 'Door', price: 100 },\n])\n\nconst filtered = collection.whereBetween('price', [100, 200])\n\nfiltered.all()\n\n// [\n//   { product: 'Desk', price: 200 },\n//   { product: 'Bookcase', price: 150 },\n//   { product: 'Door', price: 100 },\n// ]\n```\n\n#### `whereIn()`\n\nThe whereIn method filters the collection by a given key / value contained within the given array.\n\n```js\nconst collection = collect([\n  { product: 'Desk', price: 200 },\n  { product: 'Chair', price: 100 },\n  { product: 'Bookcase', price: 150 },\n  { product: 'Door', price: 100 },\n])\n\nconst filtered = collection.whereIn('price', [100, 150])\n\nfiltered.all()\n\n// [\n//   { product: 'Chair', price: 100 },\n//   { product: 'Bookcase', price: 150 },\n//   { product: 'Door', price: 100 },\n// ]\n```\n\n\u003e When working with nested objects `whereIn()` method allows dot notated keys. E.g. `whereIn('product.categories', ['office-supplies', 'furniture'])`\n\n#### `whereInstanceOf()`\n\nThe whereInstanceOf method filters the collection by a given class type:\n\n```js\nconst collection = collect([\n  new Player('Firmino'),\n  new Player('Salah'),\n  new Manager('Klopp'),\n])\n\nconst filtered = collection.whereInstanceOf(Player)\n\nfiltered.all()\n\n// [\n//   new Player('Firmino'),\n//   new Player('Salah'),\n// ]\n```\n\n#### `whereNotBetween()`\n\nThe whereNotBetween method filters the collection within a given range:\n\n```js\nconst collection = collect([\n  { product: 'Desk', price: 200 },\n  { product: 'Chair', price: 80 },\n  { product: 'Bookcase', price: 150 },\n  { product: 'Pencil', price: 30 },\n  { product: 'Door', price: 100 },\n])\n\nconst filtered = collection.whereNotBetween('price', [100, 200])\n\nfiltered.all()\n\n// [\n//   { product: 'Chair', price: 80 },\n//   { product: 'Pencil', price: 30 },\n// ]\n```\n\n#### `whereNotIn()`\n\nThe whereNotIn method filters the collection by a given key / value not contained within the given array:\n\n```js\nconst collection = collect([\n  { product: 'Desk', price: 200 },\n  { product: 'Chair', price: 100 },\n  { product: 'Bookcase', price: 150 },\n  { product: 'Door', price: 100 },\n])\n\nconst filtered = collection.whereNotIn('price', [150, 200])\n\nfiltered.all()\n\n// [\n//   { product: 'Chair', price: 100 },\n//   { product: 'Door', price: 100 },\n// ]\n```\n\n\u003e When working with nested objects `whereNotIn()` method allows dot notated keys. E.g. `whereNotIn('product .categories', ['office-supplies', 'furniture'])`\n\n#### `whereNotNull()`\n\nThe `whereNotNull` method filters items where the given key is not null.\n\n```js\nconst collection = collect([{\n  name: 'Mohamed Salah',\n}, {\n  name: null,\n}, {\n  name: 'Sadio Mané',\n}])\n\nconst filtered = collection.whereNotNull()\n\nfiltered.all()\n\n// [\n//   { name: 'Mohamed Salah' },\n//   { name: 'Sadio Mané' },\n// ]\n```\n\n#### `whereNull()`\n\nThe `whereNull` method filters items where the given key is null.\n\n```js\nconst collection = collect([{\n  name: 'Mohamed Salah',\n}, {\n  name: null,\n}, {\n  name: 'Sadio Mané',\n}])\n\nconst filtered = collection.whereNull()\n\nfiltered.all()\n\n// [\n//   { name: null },\n// ]\n```\n\n#### `wrap()`\n\nThe wrap method will wrap the given value in a collection:\n\n```js\nconst collection = collect().wrap([1, 2, 3])\n\ncollection.all()\n\n// [1, 2, 3]\n```\n\n#### `zip()`\n\nThe zip method merges together the values of the given array with the values of the original collection at the corresponding index:\n\n```js\nconst collection = collect(['Chair', 'Desk'])\n\nconst zipped = collection.zip([100, 200])\n\nzipped.all()\n\n// [['Chair', 100], ['Desk', 200]]\n```\n\n### Contribute\n\nPRs are welcomed to this project, and help is needed in order to keep up with the changes of Laravel Collections. If you want to improve the collection library, add functionality or improve the docs please feel free to submit a PR.\n\n### License\n\nMIT © [Daniel Eckermann](https://danieleckermann.com)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterroe%2Fcollect-es","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterroe%2Fcollect-es","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterroe%2Fcollect-es/lists"}