A recursive function to flatten a deeply nested array.
13 weeks ago
function flattenArray<T>(arr: any[]): T[] {
return arr.reduce(
(flat, item) =>
Array.isArray(item) ? [...flat, ...flattenArray(item)] : [...flat, item],
[] as T[]
);
}