npm-lodash

Description
A comprehensive JavaScript utility library with 296+ functions for arrays, objects, strings, and functional programming
Author
tessl
Last updated

How to use

npx @tessl/cli registry install tessl/npm-lodash@4.9.0

array-methods.md docs/

1
# Array Methods
2
3
Comprehensive array manipulation utilities for chunking, flattening, filtering, transforming, and working with arrays in JavaScript.
4
5
## Capabilities
6
7
### Cast Array
8
9
Casts value as an array if it's not one.
10
11
```javascript { .api }
12
/**
13
* Casts `value` as an array if it's not one.
14
* @param value - The value to inspect
15
* @returns Returns the cast array
16
*/
17
function castArray<T>(value?: T | T[]): T[];
18
```
19
20
### Chunk
21
22
Creates an array of elements split into groups the length of size.
23
24
```javascript { .api }
25
/**
26
* Creates an array of elements split into groups the length of `size`.
27
* @param array - The array to process
28
* @param size - The length of each chunk (defaults to 1)
29
* @returns Returns the new array of chunks
30
*/
31
function chunk<T>(array: T[], size?: number): T[][];
32
```
33
34
**Usage Examples:**
35
36
```javascript
37
import { chunk } from 'lodash';
38
39
// Basic chunking
40
const numbers = [1, 2, 3, 4, 5, 6, 7, 8];
41
console.log(chunk(numbers, 3));
42
// => [[1, 2, 3], [4, 5, 6], [7, 8]]
43
44
// Chunking with different sizes
45
console.log(chunk(numbers, 2));
46
// => [[1, 2], [3, 4], [5, 6], [7, 8]]
47
48
// Single element chunks (default)
49
console.log(chunk([1, 2, 3]));
50
// => [[1], [2], [3]]
51
52
// Common use case: pagination
53
const users = [
54
{ name: 'Alice' }, { name: 'Bob' }, { name: 'Charlie' },
55
{ name: 'David' }, { name: 'Eve' }, { name: 'Frank' }
56
];
57
const pages = chunk(users, 2); // 2 users per page
58
console.log(pages);
59
// => [
60
// [{ name: 'Alice' }, { name: 'Bob' }],
61
// [{ name: 'Charlie' }, { name: 'David' }],
62
// [{ name: 'Eve' }, { name: 'Frank' }]
63
// ]
64
```
65
66
### Compact
67
68
Creates an array with all falsey values removed.
69
70
```javascript { .api }
71
/**
72
* Creates an array with all falsey values removed. The values false, null,
73
* 0, "", undefined, and NaN are falsey.
74
* @param array - The array to compact
75
* @returns Returns the new array of filtered values
76
*/
77
function compact<T>(array: (T | null | undefined | false | 0 | "")[]): T[];
78
```
79
80
### Concat
81
82
Creates a new array concatenating array with any additional arrays and/or values.
83
84
```javascript { .api }
85
/**
86
* Creates a new array concatenating `array` with any additional arrays and/or values.
87
* @param array - The array to concatenate
88
* @param values - The values to concatenate
89
* @returns Returns the new concatenated array
90
*/
91
function concat<T>(array: T[], ...values: Array<T | T[]>): T[];
92
```
93
94
### Difference
95
96
Creates an array of unique values that are in the first array but not in the other given arrays.
97
98
```javascript { .api }
99
/**
100
* Creates an array of `array` values not included in the other given arrays
101
* using SameValueZero for equality comparisons.
102
* @param array - The array to inspect
103
* @param values - The values to exclude
104
* @returns Returns the new array of filtered values
105
*/
106
function difference<T>(array: T[], ...values: T[][]): T[];
107
```
108
109
### Difference By
110
111
Like `difference` except that it accepts `iteratee` which is invoked for each element to generate the criterion by which they're compared.
112
113
```javascript { .api }
114
/**
115
* This method is like `difference` except that it accepts `iteratee` which
116
* is invoked for each element of `array` and `values` to generate the criterion
117
* by which they're compared.
118
* @param array - The array to inspect
119
* @param values - The values to exclude
120
* @param iteratee - The iteratee invoked per element
121
* @returns Returns the new array of filtered values
122
*/
123
function differenceBy<T>(
124
array: T[],
125
values: T[],
126
iteratee?: string | ((value: T) => any)
127
): T[];
128
```
129
130
### Difference With
131
132
Like `difference` except that it accepts `comparator` which is invoked to compare elements.
133
134
```javascript { .api }
135
/**
136
* This method is like `difference` except that it accepts `comparator` which
137
* is invoked to compare elements of `array` to `values`.
138
* @param array - The array to inspect
139
* @param values - The values to exclude
140
* @param comparator - The comparator invoked per element
141
* @returns Returns the new array of filtered values
142
*/
143
function differenceWith<T>(
144
array: T[],
145
values: T[],
146
comparator?: (arrVal: T, othVal: T) => boolean
147
): T[];
148
```
149
150
### Drop
151
152
Creates a slice of array with n elements dropped from the beginning.
153
154
```javascript { .api }
155
/**
156
* Creates a slice of `array` with `n` elements dropped from the beginning.
157
* @param array - The array to query
158
* @param n - The number of elements to drop (defaults to 1)
159
* @returns Returns the slice of `array`
160
*/
161
function drop<T>(array: T[], n?: number): T[];
162
```
163
164
### Drop Right
165
166
Creates a slice of array with n elements dropped from the end.
167
168
```javascript { .api }
169
/**
170
* Creates a slice of `array` with `n` elements dropped from the end.
171
* @param array - The array to query
172
* @param n - The number of elements to drop (defaults to 1)
173
* @returns Returns the slice of `array`
174
*/
175
function dropRight<T>(array: T[], n?: number): T[];
176
```
177
178
### Drop Right While
179
180
Creates a slice of array excluding elements dropped from the end while predicate returns truthy.
181
182
```javascript { .api }
183
/**
184
* Creates a slice of `array` excluding elements dropped from the end.
185
* Elements are dropped until `predicate` returns falsey.
186
* @param array - The array to query
187
* @param predicate - The function invoked per iteration
188
* @returns Returns the slice of `array`
189
*/
190
function dropRightWhile<T>(
191
array: T[],
192
predicate?: string | object | ((value: T, index: number, array: T[]) => boolean)
193
): T[];
194
```
195
196
### Drop While
197
198
Creates a slice of array excluding elements dropped from the beginning while predicate returns truthy.
199
200
```javascript { .api }
201
/**
202
* Creates a slice of `array` excluding elements dropped from the beginning.
203
* Elements are dropped until `predicate` returns falsey.
204
* @param array - The array to query
205
* @param predicate - The function invoked per iteration
206
* @returns Returns the slice of `array`
207
*/
208
function dropWhile<T>(
209
array: T[],
210
predicate?: string | object | ((value: T, index: number, array: T[]) => boolean)
211
): T[];
212
```
213
214
### Fill
215
216
Fills elements of array with value from start up to, but not including, end.
217
218
```javascript { .api }
219
/**
220
* Fills elements of `array` with `value` from `start` up to, but not
221
* including, `end`.
222
* @param array - The array to fill
223
* @param value - The value to fill `array` with
224
* @param start - The start position (defaults to 0)
225
* @param end - The end position (defaults to array.length)
226
* @returns Returns `array`
227
*/
228
function fill<T, U>(array: T[], value: U, start?: number, end?: number): (T | U)[];
229
```
230
231
### Find Index
232
233
Finds the index of the first element predicate returns truthy for.
234
235
```javascript { .api }
236
/**
237
* This method is like `find` except that it returns the index of the first
238
* element `predicate` returns truthy for instead of the element itself.
239
* @param array - The array to inspect
240
* @param predicate - The function invoked per iteration
241
* @param fromIndex - The index to search from (defaults to 0)
242
* @returns Returns the index of the found element, else -1
243
*/
244
function findIndex<T>(
245
array: T[],
246
predicate?: string | object | ((value: T, index: number, array: T[]) => boolean),
247
fromIndex?: number
248
): number;
249
```
250
251
### Find Last Index
252
253
Like `findIndex` except that it iterates over elements from right to left.
254
255
```javascript { .api }
256
/**
257
* This method is like `findIndex` except that it iterates over elements
258
* of `collection` from right to left.
259
* @param array - The array to inspect
260
* @param predicate - The function invoked per iteration
261
* @param fromIndex - The index to search from (defaults to array.length - 1)
262
* @returns Returns the index of the found element, else -1
263
*/
264
function findLastIndex<T>(
265
array: T[],
266
predicate?: string | object | ((value: T, index: number, array: T[]) => boolean),
267
fromIndex?: number
268
): number;
269
```
270
271
### Flatten
272
273
Flattens array a single level deep.
274
275
```javascript { .api }
276
/**
277
* Flattens `array` a single level deep.
278
* @param array - The array to flatten
279
* @returns Returns the new flattened array
280
*/
281
function flatten<T>(array: T[] | T[][]): T[];
282
```
283
284
### Flatten Deep
285
286
Recursively flattens array.
287
288
```javascript { .api }
289
/**
290
* Recursively flattens `array`.
291
* @param array - The array to flatten
292
* @returns Returns the new flattened array
293
*/
294
function flattenDeep<T>(array: any[]): T[];
295
```
296
297
### Flatten Depth
298
299
Recursively flatten array up to depth times.
300
301
```javascript { .api }
302
/**
303
* Recursively flatten `array` up to `depth` times.
304
* @param array - The array to flatten
305
* @param depth - The maximum recursion depth (defaults to 1)
306
* @returns Returns the new flattened array
307
*/
308
function flattenDepth<T>(array: any[], depth?: number): T[];
309
```
310
311
### From Pairs
312
313
Returns an object composed from key-value pairs.
314
315
```javascript { .api }
316
/**
317
* Returns an object composed from key-value `pairs`.
318
* @param pairs - The key-value pairs
319
* @returns Returns the new object
320
*/
321
function fromPairs<T>(pairs: Array<[PropertyKey, T]>): Record<string, T>;
322
```
323
324
### Head
325
326
Gets the first element of array.
327
328
```javascript { .api }
329
/**
330
* Gets the first element of `array`.
331
* @param array - The array to query
332
* @returns Returns the first element of `array`
333
*/
334
function head<T>(array: T[]): T | undefined;
335
```
336
337
### Index Of
338
339
Gets the index at which the first occurrence of value is found in array.
340
341
```javascript { .api }
342
/**
343
* Gets the index at which the first occurrence of `value` is found in `array`
344
* using SameValueZero for equality comparisons.
345
* @param array - The array to inspect
346
* @param value - The value to search for
347
* @param fromIndex - The index to search from (defaults to 0)
348
* @returns Returns the index of the matched value, else -1
349
*/
350
function indexOf<T>(array: T[], value: T, fromIndex?: number): number;
351
```
352
353
### Initial
354
355
Gets all but the last element of array.
356
357
```javascript { .api }
358
/**
359
* Gets all but the last element of `array`.
360
* @param array - The array to query
361
* @returns Returns the slice of `array`
362
*/
363
function initial<T>(array: T[]): T[];
364
```
365
366
### Intersection
367
368
Creates an array of unique values that are included in all given arrays.
369
370
```javascript { .api }
371
/**
372
* Creates an array of unique values that are included in all given arrays
373
* using SameValueZero for equality comparisons.
374
* @param arrays - The arrays to inspect
375
* @returns Returns the new array of intersecting values
376
*/
377
function intersection<T>(...arrays: T[][]): T[];
378
```
379
380
### Intersection By
381
382
Like `intersection` except that it accepts `iteratee` which is invoked for each element to generate the criterion by which they're compared.
383
384
```javascript { .api }
385
/**
386
* This method is like `intersection` except that it accepts `iteratee`
387
* which is invoked for each element of each `arrays` to generate the criterion
388
* by which they're compared.
389
* @param arrays - The arrays to inspect
390
* @param iteratee - The iteratee invoked per element
391
* @returns Returns the new array of intersecting values
392
*/
393
function intersectionBy<T>(
394
array: T[],
395
...args: Array<T[] | string | ((value: T) => any)>
396
): T[];
397
```
398
399
### Intersection With
400
401
Like `intersection` except that it accepts `comparator` which is invoked to compare elements.
402
403
```javascript { .api }
404
/**
405
* This method is like `intersection` except that it accepts `comparator`
406
* which is invoked to compare elements of `arrays`.
407
* @param arrays - The arrays to inspect
408
* @param comparator - The comparator invoked per element
409
* @returns Returns the new array of intersecting values
410
*/
411
function intersectionWith<T>(
412
array: T[],
413
...args: Array<T[] | ((arrVal: T, othVal: T) => boolean)>
414
): T[];
415
```
416
417
### Join
418
419
Converts all elements in array into a string separated by separator.
420
421
```javascript { .api }
422
/**
423
* Converts all elements in `array` into a string separated by `separator`.
424
* @param array - The array to convert
425
* @param separator - The element separator (defaults to ',')
426
* @returns Returns the joined string
427
*/
428
function join<T>(array: T[], separator?: string): string;
429
```
430
431
### Last
432
433
Gets the last element of array.
434
435
```javascript { .api }
436
/**
437
* Gets the last element of `array`.
438
* @param array - The array to query
439
* @returns Returns the last element of `array`
440
*/
441
function last<T>(array: T[]): T | undefined;
442
```
443
444
### Last Index Of
445
446
Gets the index at which the last occurrence of value is found in array.
447
448
```javascript { .api }
449
/**
450
* This method is like `indexOf` except that it iterates over elements of
451
* `array` from right to left.
452
* @param array - The array to inspect
453
* @param value - The value to search for
454
* @param fromIndex - The index to search from (defaults to array.length - 1)
455
* @returns Returns the index of the matched value, else -1
456
*/
457
function lastIndexOf<T>(array: T[], value: T, fromIndex?: number): number;
458
```
459
460
### Pull
461
462
Removes all given values from array using SameValueZero for equality comparisons.
463
464
```javascript { .api }
465
/**
466
* Removes all given values from `array` using SameValueZero for equality comparisons.
467
* @param array - The array to modify
468
* @param values - The values to remove
469
* @returns Returns `array`
470
*/
471
function pull<T>(array: T[], ...values: T[]): T[];
472
```
473
474
### Pull All
475
476
Like `pull` except that it accepts an array of values to remove.
477
478
```javascript { .api }
479
/**
480
* This method is like `pull` except that it accepts an array of values to remove.
481
* @param array - The array to modify
482
* @param values - The values to remove
483
* @returns Returns `array`
484
*/
485
function pullAll<T>(array: T[], values: T[]): T[];
486
```
487
488
### Pull All By
489
490
Like `pullAll` except that it accepts `iteratee` which is invoked for each element to generate the criterion by which they're compared.
491
492
```javascript { .api }
493
/**
494
* This method is like `pullAll` except that it accepts `iteratee` which is
495
* invoked for each element of `array` and `values` to generate the criterion
496
* by which they're compared.
497
* @param array - The array to modify
498
* @param values - The values to remove
499
* @param iteratee - The iteratee invoked per element
500
* @returns Returns `array`
501
*/
502
function pullAllBy<T>(
503
array: T[],
504
values: T[],
505
iteratee?: string | ((value: T) => any)
506
): T[];
507
```
508
509
### Pull All With
510
511
Like `pullAll` except that it accepts `comparator` which is invoked to compare elements.
512
513
```javascript { .api }
514
/**
515
* This method is like `pullAll` except that it accepts `comparator` which
516
* is invoked to compare elements of `array` to `values`.
517
* @param array - The array to modify
518
* @param values - The values to remove
519
* @param comparator - The comparator invoked per element
520
* @returns Returns `array`
521
*/
522
function pullAllWith<T>(
523
array: T[],
524
values: T[],
525
comparator?: (arrVal: T, othVal: T) => boolean
526
): T[];
527
```
528
529
### Pull At
530
531
Removes elements from array corresponding to indexes and returns an array of removed elements.
532
533
```javascript { .api }
534
/**
535
* Removes elements from `array` corresponding to `indexes` and returns an
536
* array of removed elements.
537
* @param array - The array to modify
538
* @param indexes - The indexes of elements to remove
539
* @returns Returns the new array of removed elements
540
*/
541
function pullAt<T>(array: T[], ...indexes: number[]): T[];
542
```
543
544
### Remove
545
546
Removes all elements from array that predicate returns truthy for and returns an array of the removed elements.
547
548
```javascript { .api }
549
/**
550
* Removes all elements from `array` that `predicate` returns truthy for
551
* and returns an array of the removed elements.
552
* @param array - The array to modify
553
* @param predicate - The function invoked per iteration
554
* @returns Returns the new array of removed elements
555
*/
556
function remove<T>(
557
array: T[],
558
predicate: string | object | ((value: T, index: number, array: T[]) => boolean)
559
): T[];
560
```
561
562
### Reverse
563
564
Reverses array so that the first element becomes the last, the second element becomes the second to last, and so on.
565
566
```javascript { .api }
567
/**
568
* Reverses `array` so that the first element becomes the last, the second
569
* element becomes the second to last, and so on.
570
* @param array - The array to modify
571
* @returns Returns `array`
572
*/
573
function reverse<T>(array: T[]): T[];
574
```
575
576
### Slice
577
578
Creates a slice of array from start up to, but not including, end.
579
580
```javascript { .api }
581
/**
582
* Creates a slice of `array` from `start` up to, but not including, `end`.
583
* @param array - The array to slice
584
* @param start - The start position (defaults to 0)
585
* @param end - The end position (defaults to array.length)
586
* @returns Returns the slice of `array`
587
*/
588
function slice<T>(array: T[], start?: number, end?: number): T[];
589
```
590
591
### Sorted Index
592
593
Uses a binary search to determine the lowest index at which value should be inserted into array in order to maintain its sort order.
594
595
```javascript { .api }
596
/**
597
* Uses a binary search to determine the lowest index at which `value`
598
* should be inserted into `array` in order to maintain its sort order.
599
* @param array - The sorted array to inspect
600
* @param value - The value to evaluate
601
* @returns Returns the index at which `value` should be inserted
602
*/
603
function sortedIndex<T>(array: T[], value: T): number;
604
```
605
606
### Sorted Index By
607
608
Like `sortedIndex` except that it accepts `iteratee` which is invoked for `value` and each element of `array` to compute their sort ranking.
609
610
```javascript { .api }
611
/**
612
* This method is like `sortedIndex` except that it accepts `iteratee`
613
* which is invoked for `value` and each element of `array` to compute their
614
* sort ranking.
615
* @param array - The sorted array to inspect
616
* @param value - The value to evaluate
617
* @param iteratee - The iteratee invoked per element
618
* @returns Returns the index at which `value` should be inserted
619
*/
620
function sortedIndexBy<T>(
621
array: T[],
622
value: T,
623
iteratee?: string | ((value: T) => any)
624
): number;
625
```
626
627
### Sorted Index Of
628
629
Performs a binary search on a sorted array to find the index of the first occurrence of a value.
630
631
```javascript { .api }
632
/**
633
* This method is like `indexOf` except that it performs a binary search
634
* on a sorted `array`.
635
* @param array - The array to inspect
636
* @param value - The value to search for
637
* @returns Returns the index of the matched value, else -1
638
*/
639
function sortedIndexOf<T>(array: T[], value: T): number;
640
```
641
642
### Sorted Last Index
643
644
Uses a binary search to determine the highest index at which value should be inserted into array in order to maintain its sort order.
645
646
```javascript { .api }
647
/**
648
* This method is like `sortedIndex` except that it returns the highest
649
* index at which `value` should be inserted into `array` in order to
650
* maintain its sort order.
651
* @param array - The sorted array to inspect
652
* @param value - The value to evaluate
653
* @returns Returns the index at which `value` should be inserted
654
*/
655
function sortedLastIndex<T>(array: T[], value: T): number;
656
```
657
658
### Sorted Last Index By
659
660
Like `sortedLastIndex` except that it accepts `iteratee` which is invoked for `value` and each element of `array` to compute their sort ranking.
661
662
```javascript { .api }
663
/**
664
* This method is like `sortedLastIndex` except that it accepts `iteratee`
665
* which is invoked for `value` and each element of `array` to compute their
666
* sort ranking.
667
* @param array - The sorted array to inspect
668
* @param value - The value to evaluate
669
* @param iteratee - The iteratee invoked per element
670
* @returns Returns the index at which `value` should be inserted
671
*/
672
function sortedLastIndexBy<T>(
673
array: T[],
674
value: T,
675
iteratee?: string | ((value: T) => any)
676
): number;
677
```
678
679
### Sorted Last Index Of
680
681
Performs a binary search on a sorted array to find the index of the last occurrence of a value.
682
683
```javascript { .api }
684
/**
685
* This method is like `lastIndexOf` except that it performs a binary
686
* search on a sorted `array`.
687
* @param array - The array to inspect
688
* @param value - The value to search for
689
* @returns Returns the index of the matched value, else -1
690
*/
691
function sortedLastIndexOf<T>(array: T[], value: T): number;
692
```
693
694
### Sorted Uniq
695
696
Creates a duplicate-free version of an array, using SameValueZero for equality comparisons, in which only the first occurrence of each element is kept. The order of result values is determined by the order they occur in the array.
697
698
```javascript { .api }
699
/**
700
* This method is like `uniq` except that it's designed and optimized
701
* for sorted arrays.
702
* @param array - The array to inspect
703
* @returns Returns the new duplicate free array
704
*/
705
function sortedUniq<T>(array: T[]): T[];
706
```
707
708
### Sorted Uniq By
709
710
Like `sortedUniq` except that it accepts `iteratee` which is invoked for each element to generate the criterion by which uniqueness is computed.
711
712
```javascript { .api }
713
/**
714
* This method is like `uniqBy` except that it's designed and optimized
715
* for sorted arrays.
716
* @param array - The array to inspect
717
* @param iteratee - The iteratee invoked per element
718
* @returns Returns the new duplicate free array
719
*/
720
function sortedUniqBy<T>(
721
array: T[],
722
iteratee: string | ((value: T) => any)
723
): T[];
724
```
725
726
### Tail
727
728
Gets all but the first element of array.
729
730
```javascript { .api }
731
/**
732
* Gets all but the first element of `array`.
733
* @param array - The array to query
734
* @returns Returns the slice of `array`
735
*/
736
function tail<T>(array: T[]): T[];
737
```
738
739
### Take
740
741
Creates a slice of array with n elements taken from the beginning.
742
743
```javascript { .api }
744
/**
745
* Creates a slice of `array` with `n` elements taken from the beginning.
746
* @param array - The array to query
747
* @param n - The number of elements to take (defaults to 1)
748
* @returns Returns the slice of `array`
749
*/
750
function take<T>(array: T[], n?: number): T[];
751
```
752
753
### Take Right
754
755
Creates a slice of array with n elements taken from the end.
756
757
```javascript { .api }
758
/**
759
* Creates a slice of `array` with `n` elements taken from the end.
760
* @param array - The array to query
761
* @param n - The number of elements to take (defaults to 1)
762
* @returns Returns the slice of `array`
763
*/
764
function takeRight<T>(array: T[], n?: number): T[];
765
```
766
767
### Take Right While
768
769
Creates a slice of array with elements taken from the end while predicate returns truthy.
770
771
```javascript { .api }
772
/**
773
* Creates a slice of `array` with elements taken from the end. Elements are
774
* taken until `predicate` returns falsey.
775
* @param array - The array to query
776
* @param predicate - The function invoked per iteration
777
* @returns Returns the slice of `array`
778
*/
779
function takeRightWhile<T>(
780
array: T[],
781
predicate?: string | object | ((value: T, index: number, array: T[]) => boolean)
782
): T[];
783
```
784
785
### Take While
786
787
Creates a slice of array with elements taken from the beginning while predicate returns truthy.
788
789
```javascript { .api }
790
/**
791
* Creates a slice of `array` with elements taken from the beginning. Elements
792
* are taken until `predicate` returns falsey.
793
* @param array - The array to query
794
* @param predicate - The function invoked per iteration
795
* @returns Returns the slice of `array`
796
*/
797
function takeWhile<T>(
798
array: T[],
799
predicate?: string | object | ((value: T, index: number, array: T[]) => boolean)
800
): T[];
801
```
802
803
### Union
804
805
Creates an array of unique values, in order, from all given arrays using SameValueZero for equality comparisons.
806
807
```javascript { .api }
808
/**
809
* Creates an array of unique values, in order, from all given arrays using
810
* SameValueZero for equality comparisons.
811
* @param arrays - The arrays to inspect
812
* @returns Returns the new array of combined values
813
*/
814
function union<T>(...arrays: T[][]): T[];
815
```
816
817
### Union By
818
819
Like `union` except that it accepts `iteratee` which is invoked for each element to generate the criterion by which uniqueness is computed.
820
821
```javascript { .api }
822
/**
823
* This method is like `union` except that it accepts `iteratee` which is
824
* invoked for each element of each `arrays` to generate the criterion by
825
* which uniqueness is computed.
826
* @param arrays - The arrays to inspect
827
* @param iteratee - The iteratee invoked per element
828
* @returns Returns the new array of combined values
829
*/
830
function unionBy<T>(
831
array: T[],
832
...args: Array<T[] | string | ((value: T) => any)>
833
): T[];
834
```
835
836
### Union With
837
838
Like `union` except that it accepts `comparator` which is invoked to compare elements.
839
840
```javascript { .api }
841
/**
842
* This method is like `union` except that it accepts `comparator` which
843
* is invoked to compare elements of `arrays`.
844
* @param arrays - The arrays to inspect
845
* @param comparator - The comparator invoked per element
846
* @returns Returns the new array of combined values
847
*/
848
function unionWith<T>(
849
array: T[],
850
...args: Array<T[] | ((arrVal: T, othVal: T) => boolean)>
851
): T[];
852
```
853
854
### Uniq
855
856
Creates a duplicate-free version of an array using SameValueZero for equality comparisons.
857
858
```javascript { .api }
859
/**
860
* Creates a duplicate-free version of an array, using SameValueZero for
861
* equality comparisons, in which only the first occurrence of each element
862
* is kept. The order of result values is determined by the order they occur
863
* in the array.
864
* @param array - The array to inspect
865
* @returns Returns the new duplicate free array
866
*/
867
function uniq<T>(array: T[]): T[];
868
```
869
870
### Uniq By
871
872
Like `uniq` except that it accepts `iteratee` which is invoked for each element to generate the criterion by which uniqueness is computed.
873
874
```javascript { .api }
875
/**
876
* This method is like `uniq` except that it accepts `iteratee` which is
877
* invoked for each element in `array` to generate the criterion by which
878
* uniqueness is computed.
879
* @param array - The array to inspect
880
* @param iteratee - The iteratee invoked per element
881
* @returns Returns the new duplicate free array
882
*/
883
function uniqBy<T>(
884
array: T[],
885
iteratee: string | ((value: T) => any)
886
): T[];
887
```
888
889
### Uniq With
890
891
Like `uniq` except that it accepts `comparator` which is invoked to compare elements.
892
893
```javascript { .api }
894
/**
895
* This method is like `uniq` except that it accepts `comparator` which
896
* is invoked to compare elements of `array`.
897
* @param array - The array to inspect
898
* @param comparator - The comparator invoked per element
899
* @returns Returns the new duplicate free array
900
*/
901
function uniqWith<T>(
902
array: T[],
903
comparator?: (arrVal: T, othVal: T) => boolean
904
): T[];
905
```
906
907
### Unzip
908
909
Accepts an array of grouped elements and creates an array regrouping the elements to their pre-zip configuration.
910
911
```javascript { .api }
912
/**
913
* This method is like `zip` except that it accepts an array of grouped
914
* elements and creates an array regrouping the elements to their pre-zip
915
* configuration.
916
* @param array - The array of grouped elements to process
917
* @returns Returns the new array of regrouped elements
918
*/
919
function unzip<T>(array: T[][]): T[][];
920
```
921
922
### Unzip With
923
924
Like `unzip` except that it accepts `iteratee` to specify how regrouped values should be combined.
925
926
```javascript { .api }
927
/**
928
* This method is like `unzip` except that it accepts `iteratee` to specify
929
* how regrouped values should be combined.
930
* @param array - The array of grouped elements to process
931
* @param iteratee - The function to combine regrouped values
932
* @returns Returns the new array of regrouped elements
933
*/
934
function unzipWith<T, R>(
935
array: T[][],
936
iteratee?: (...values: T[]) => R
937
): R[];
938
```
939
940
### Without
941
942
Creates an array excluding all given values using SameValueZero for equality comparisons.
943
944
```javascript { .api }
945
/**
946
* Creates an array excluding all given values using SameValueZero for
947
* equality comparisons.
948
* @param array - The array to inspect
949
* @param values - The values to exclude
950
* @returns Returns the new array of filtered values
951
*/
952
function without<T>(array: T[], ...values: T[]): T[];
953
```
954
955
### Xor
956
957
Creates an array of unique values that is the symmetric difference of the given arrays.
958
959
```javascript { .api }
960
/**
961
* Creates an array of unique values that is the symmetric difference of
962
* the given arrays. The order of result values is determined by the order
963
* they occur in the arrays.
964
* @param arrays - The arrays to inspect
965
* @returns Returns the new array of filtered values
966
*/
967
function xor<T>(...arrays: T[][]): T[];
968
```
969
970
### Xor By
971
972
Like `xor` except that it accepts `iteratee` which is invoked for each element to generate the criterion by which they're compared.
973
974
```javascript { .api }
975
/**
976
* This method is like `xor` except that it accepts `iteratee` which is
977
* invoked for each element of each `arrays` to generate the criterion by
978
* which by which they're compared.
979
* @param arrays - The arrays to inspect
980
* @param iteratee - The iteratee invoked per element
981
* @returns Returns the new array of filtered values
982
*/
983
function xorBy<T>(
984
array: T[],
985
...args: Array<T[] | string | ((value: T) => any)>
986
): T[];
987
```
988
989
### Xor With
990
991
Like `xor` except that it accepts `comparator` which is invoked to compare elements.
992
993
```javascript { .api }
994
/**
995
* This method is like `xor` except that it accepts `comparator` which is
996
* invoked to compare elements of `arrays`.
997
* @param arrays - The arrays to inspect
998
* @param comparator - The comparator invoked per element
999
* @returns Returns the new array of filtered values
1000
*/
1001
function xorWith<T>(
1002
array: T[],
1003
...args: Array<T[] | ((arrVal: T, othVal: T) => boolean)>
1004
): T[];
1005
```
1006
1007
### Zip
1008
1009
Creates an array of grouped elements, the first of which contains the first elements of the given arrays, the second of which contains the second elements of the given arrays, and so on.
1010
1011
```javascript { .api }
1012
/**
1013
* Creates an array of grouped elements, the first of which contains the
1014
* first elements of the given arrays, the second of which contains the
1015
* second elements of the given arrays, and so on.
1016
* @param arrays - The arrays to process
1017
* @returns Returns the new array of grouped elements
1018
*/
1019
function zip<T>(...arrays: T[][]): T[][];
1020
```
1021
1022
### Zip Object
1023
1024
Creates an object composed from arrays of keys and values.
1025
1026
```javascript { .api }
1027
/**
1028
* This method is like `fromPairs` except that it accepts two arrays,
1029
* one of property identifiers and one of corresponding values.
1030
* @param keys - The property identifiers
1031
* @param values - The property values
1032
* @returns Returns the new object
1033
*/
1034
function zipObject<K extends PropertyKey, V>(keys: K[], values: V[]): Record<K, V>;
1035
```
1036
1037
### Zip Object Deep
1038
1039
Like `zipObject` except that it supports property paths.
1040
1041
```javascript { .api }
1042
/**
1043
* This method is like `zipObject` except that it supports property paths.
1044
* @param paths - The property identifiers
1045
* @param values - The property values
1046
* @returns Returns the new object
1047
*/
1048
function zipObjectDeep(paths: string[], values: any[]): any;
1049
```
1050
1051
### Zip With
1052
1053
Like `zip` except that it accepts `iteratee` to specify how grouped values should be combined.
1054
1055
```javascript { .api }
1056
/**
1057
* This method is like `zip` except that it accepts `iteratee` to specify
1058
* how grouped values should be combined.
1059
* @param arrays - The arrays to process
1060
* @param iteratee - The function to combine grouped values
1061
* @returns Returns the new array of grouped elements
1062
*/
1063
function zipWith<T, R>(
1064
array: T[],
1065
...args: Array<T[] | ((...values: T[]) => R)>
1066
): R[];
1067
```
1068
1069
## Types
1070
1071
```javascript { .api }
1072
type PropertyKey = string | number | symbol;
1073
```
1074
1075
## Aliases
1076
1077
- `first``head`