EN
TypeScript - clone array
0
points
In this article, we would like to show you how to clone an array in TypeScript.
Quick solution:
const letters: string[] = ['A', 'B', 'C'];
const copy: string[] = letters.slice();
console.log(letters); // [ 'A', 'B', 'C' ]
console.log(copy); // [ 'A', 'B', 'C' ]
Output:
[ 'A', 'B', 'C' ]
[ 'A', 'B', 'C' ]