let myObj= [
{ "ean":1, "name":'prod1', "attibutes":[{"attr": 100,"color": "green"},{"attr": 200,"color": "red"}] },
{ "ean":2, "name":'prod1', "attibutes":[{"attr": 100,"color": "white"},{"attr": 200,"color": "blu"}] }
];
function toCsv(arrOfObj){
const csvString = [
...arrOfObj.map(item => [
item.ean,
item.name,
Object.keys(item.attibutes).map(row => [ Object.keys(item.attibutes[row]).map( elkey => elkey + ':' + item.attibutes[row][elkey] )])
])]
.map(e => e.join(";"))
.join("
");
console.log(csvString);
return csvString;
}
toCsv(myObj);