forEach
does not return. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/forEach#Return_value
Use map
instead. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/map#Return_value
Also, to use map
options must be an array.
Check out this example.
var options = Array.from(document.getElementById('selections').options),
newOptions = options.map(function(item){
return item.value
});
console.log(newOptions);
document.getElementById('results').insertAdjacentHTML('afterbegin', newOptions.reduce((a,b) => a.concat(`${b} `), ' '));
returning from forEach javascript