Write a function called flattenArray that takes in an array containing nested arrays of integers and returns a new array with all the integers from the nested arrays flattened into a single level.
/**
* Returns a flattened array.
* @param {number[]} arr - The array containing nested arrays.
* @returns {number[]} - The flattened array.
*/
function flattenArray(arr: number[]): number[];
flattenArray([1, [2, 3], [4, 5, [6]]]); // should return [1, 2, 3, 4, 5, 6]
flattenArray([
[1, 2],
[3, [4, 5]],
[6, [7]],
]); // should return [1, 2, 3, 4, 5, 6, 7]
flattenArray([1, [2, [3, [4, [5]]]]]); // should return [1, 2, 3, 4, 5]
flattenArray function on that element to flatten it further.result to store the flattened array.for...of loop.flattenArray function on that element to flatten it further, and then concatenate the result to the result array.result array.result array.The base case is implicitly handled within the loop structure. As the loop iterates through each element of the input array arr, the recursion eventually reaches the point where there are no more elements left to process.