Seeking advice from a newcomer...
I am attempting to develop a function that takes an array and an empty string as parameters. The function should use the .join() method on the array and assign the result to the empty string provided.
Although the function successfully joins the array elements (confirmed with console.log), it unfortunately doesn't set the result to the external variable. What could be the issue here?
Here is the code snippet:
//initializing empty string
var newStr = '';
var myArr = ['it', 'was', 'the', 'best', 'of', 'times'];
var rejoiner = function(arr, str) {
str = arr.join(' ');
//verifying the function's functionality
console.log(str);
}
Next, execute the rejoiner
function by passing in the myArr
and newStr
...
rejoiner(myArr, newStr);
Finally, check if newStr
has been updated (unfortunately, not updated!)...
newStr;