I want to flat an array, recursion function calls itself till the last element array but not the last element string, I feel like I am missing something important in understanding how recursion works, the string itself is not added to an empty array.
const nested = [[[[[['string']]]]], 5, '7'];
const funcTest = function (arr) {
const final = [];
arr.forEach(el => {
if (Array.isArray(el)) {
console.log(el);
funcTest(el);
} else final.push(el);
});
return final;
};
console.log(funcTest(nested));
.flat? Consider[[[[[['string']]]]], 5, '7'].flat(Infinity)