This function empties an array, removing all its elements.
JavaScript:
let emptyArray = arr => arr.length = 0;
// Example
let arr = [1, 2, 3]; emptyArray(arr); console.log(arr); // []
let arr2 = ['a', 'b', 'c']; emptyArray(arr2); console.log(arr2); // []
TypeScript:
let emptyArray = (arr: any[]): void => { arr.length = 0; };
// Example
let arr: number[] = [1, 2, 3]; emptyArray(arr); console.log(arr); // []
let arr2: string[] = ['a', 'b', 'c']; emptyArray(arr2); console.log(arr2); // []