![]() |
VOOZH | about |
Lodash _.partition() method creates an array of elements split into two groups, the first of which contains elements predicate returns true and the second of which contains elements predicate returns false.
_.partition(collection, predicate);Return Value: This method returns the array of grouped elements.
Example 1: In this example, we are partitioning our array into two parts one which has true as an active value and another is false as an active value.
Output:
[
[ { customer: 'jonny', age: 34, active: true } ],
[
{ customer: 'john', age: 26, active: false },
{ customer: 'johnson', age: 12, active: false }
]
]
Example 2: In this example, we are partitioning our array into two parts. we are passing our condition as an object into the _.partitiion() method.
Output:
[
[ { customer: 'johnson', age: 12, active: false } ],
[
{ customer: 'john', age: 26, active: false },
{ customer: 'jonny', age: 34, active: true }
]
]
Example 3: In this example, we are partitioning our array into two parts. we are passing our condition as an array into the _.partitiion() method.
Output:
[
[
{ customer: 'john', age: 26, active: false },
{ customer: 'johnson', age: 12, active: false }
],
[ { customer: 'jonny', age: 34, active: true } ]
]