I am attempting to use the reduce method on an object to create an HTML list
const dropdownTemplate = (data) => {
console.log(data); // no data displayed
return `
<li class="dropdown__item" data-value="${data.value}"><span class="dropdown__itemCode">${data.code}</span> <span class="dropdown__itemText">${data.name}</span></li>
`;
};
const data_obj = JSON.parse('[ { "type": "hotel", "value": 25, "name":"Hotel name", "code": "sn", "lat" : "1.3", "long" : "1.33" } ]');
const fetched_items = data_obj.reduce((item, generated) => {
generated += dropdownTemplate(item);
return generated;
}, '');
console.log(fetched_items); // always contains undefined values
However, I can't figure out why the item is always empty (resulting in a list with undefined values).
What mistake am I making here?