// Previous Way
function getListData(data) {
const items = [];
if (!data) return [];
for (const [index, item] of Object.entries(data)) {
const name = item.name;
const category = item.category;
const web = item.website;
const obj = {
name,
category,
web,
};
items.push(obj);
}
return items;
}
// Cleaner Solution - new way
function getListData(data) {
if (!data) return [];
return Object.entries(data).map(([index, item]) => ({
name: item.name,
category: item.category,
web: item.website,
}));
}
const getData = getListData(dummyData)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter