I am a beginner in javascript. I have to perform a recursive function allowing me to output the concatenated names of the array as a string. Has very little, I am there, except my last value is given to me in undefined
const userNames = ['Elon', 'Susan', 'Bill', 'Marika', 'Ryan'];
function name(i) {
if (i < userNames.length) {
var names = userNames[i] + ' - ' + name(++i);
return names;
} else {
console.log(names);
};
}
name(0);
thx all
userNames.join(" - ")???elsecase.