Simple question from a newbie here...
I am trying to create a function that accepts an array and an empty string. The function will then perform the .join() method on the array, and is supposed to set the result to the empty string.
The function seems to join (checked with console.log), however it doesn't set the result to the variable outside. What am I missing here?
The code
//empty string
var newStr ='';
var myArr = ['it','was', 'the', 'best', 'of', 'times'];
var rejoiner = function (arr, str) {
str = arr.join(' ');
//checking that the function is working
console.log(str);
}
Then, run the function rejoiner
, passing in myArr
and newStr
...
rejoiner(myArr, newStr);
Then check to see if newStr was set (failure! not set!)...
newStr;