To join arrays in TypeScript, you can use the concat
method or the spread operator (...)
.
In this example,
arr1
and arr2
.concat
method to concatenate arr1
and arr2
into a new array result
.result
array contains elements from both arr1
and arr2
.const arr1: number[] = [1, 2, 3];
const arr2: number[] = [4, 5, 6];
const result: number[] = arr1.concat(arr2);
console.log('Joined Array:', result);
Joined Array: [ 1, 2, 3, 4, 5, 6 ]
In this example,
arr1
and arr2
.(...)
to spread elements of arr1
and arr2
into a new array result
.result
array contains elements from both arr1
and arr2
.const arr1: number[] = [1, 2, 3];
const arr2: number[] = [4, 5, 6];
const result: number[] = [...arr1, ...arr2];
console.log('Joined Array:', result);
Joined Array: [ 1, 2, 3, 4, 5, 6 ]
In this tutorial, we learned How to Join Arrays in TypeScript language with well detailed examples.