mergeArray()function

mergeArray(left: ImmutableArray<L>, right: ImmutableArray<R> | ImmutableArray<L>): ImmutableArray<L | R>
ParamType
leftImmutableArray<L>
The left array to merge into. required
rightImmutableArray<R>
ImmutableArray<L>
The right array whose unique items are merged in. required
Return
ImmutableArray<L | R>
Merged array.
- Values that appear in both arrays will not be added twice.
- Will be left instance if no items were added.
- Will be a new merged array otherwise.

Merge two arrays.

  • Values are considered unique so values will not appear twice.
  • Arrays have no concept of deep merge because array keys are not stable.
  • Use an map/object data structure instead for values that need to be deeply mergeable (only use arrays for primitive values).

Examples

mergeArray([1, 2], [2, 3]) // [1, 2, 3]