Skip to content

Function: mergeArray() ​

mergeArray<T, U>(arr1, arr2): (T | U)[]

Concatenate two arrays into a new one: the items of the first, then the items of the second. The duplicates are kept (see uniqueArray to remove them) and neither array is modified.

Type Parameters ​

T ​

T = any

U ​

U = any

Parameters ​

arr1 ​

T[]

The first items.

arr2 ​

U[]

The items appended after them.

Returns ​

(T | U)[]

A new array of arr1.length + arr2.length items.

Example ​

typescript
import {mergeArray} from 'lakutata/utils'

console.log(mergeArray([1, 2], [2, 3]))
//[1, 2, 2, 3]

Released under the MIT License.