I am trying to print the values inside the memo object, but I am getting undefined while is clear that there is values inside the memo object, or even iterating the object to get the values, please help.
let arr = [1, 2, 3, 4];
function iter(arr, n, memo = {}) {
if (n < arr.length) {
memo[n] = iter(arr, n + 1);
}
// iterate memo object and print the values
// memo = { '0': { '1': { '2': [Object] } } }
for (let i in memo) {
console.log(memo[i]);
// I am getting undefined
}
// also here when I return the first value I am gettng undefined
//
return memo["0"];
}
console.log(iter(arr, 0));