What will be the output of the following recursive function?
function flattenArray(arr) {
let flattened = [];
arr.forEach(element => {
if (Array.isArray(element)) {
flattened.push(...flattenArray(element));
} else {
flattened.push(element);
}
});
return flattened;
}
console.log(flattenArray([1, [2, 3], [4, [5, 6]]]));