let data = {cat:1,dog:2};
Object.keys(data).map(async (id) => {
await appendFile(fileName, id);
await appendFile(fileName, data[id]);
});
async function saveData(data) {
for(let id of Object.keys(data)) {
await appendFile(fileName, id);
await appendFile(fileName, data[id]);
}
}
saveData({cat:1,dog:2})
let data = {cat:1,dog:2};
Object.keys(data).reduce(
(p, id) => p
.then(() => appendFile(fileName, id))
.then(() => appendFile(fileName, data[id])),
Promise.resolve()
);