I have an object like this:-
{
"SUCCESS": [
"apple",
"orange",
"grapes"
],
"FAILED": ["kiwi"],
"NOPE": ["peach"]
}
I want to have a CSV as follows:-
apple SUCCESS
orange SUCCESS
grapes SUCCESS
kiwi FAILED
peach NOPE
I figured out this piece of code but unable to iterate over this:-
const downLoadCsv = (key, items) => {
let csvContent = '';
if (!items.length) {
return;
}
items.forEach((item) => {
csvContent += `${item},`;
csvContent += '\n';
});
const anchorEle = document.createElement('a');
anchorEle.href = `data:text/csv;charset=utf-8,${encodeURI(csvContent)}`;
anchorEle.target = '_blank';
anchorEle.download = `${key}.csv`;
anchorEle.click();
};