I have a simple function to get value from nested arrays:
function getVal(arr){
var el = arr[0];
console.log(el);
console.log(Array.isArray(el));
if(Array.isArray(el)){
getVal(el);
}else{
return el;
}
}
And I get undefined all the time. Here is the console output:
getVal([["a"]]);
["a"]
true
"a"
false
undefined
As far as I understand, when el === "a" condition if(Array.isArray(el)) is satisfied and I get recursive call with getVal("a"), which gives undefined result. What's happening there? And why "a" is not returned?