I have following code within render method:
return (<select>
{[...Array(24).keys()].reduce((acc, item) => `${acc} <option value="${item}">${item}<option>`, '')}
</select>);
acc variable contains all options, and reduce() function has implicit return but no options are displayed. What is explanation behind this?
I was able to make this work with .map(), I'm just curious what is the problem with the reduce function in the above example.
<select>
{[...Array(24).keys()].map(hour => {
return <option value={hour} key={hour}>{hour}</option>
})
}
</select>
Thanks