Reputation: 1007
I have an Angular app and I am getting the contents of a json file from Google Drive. The contents is an array of 1011 customers that I want to transform into an object. However the reduce function always returns an empty object. Inside the function, when I check for a value of the key I want to use, the debugger says it is undefined, although it is not when I log the object to the console. Can you identify what is going wrong?
private getCustomers() {
return this.httpSrv.getFileContent(this.customersFileId).then((res)
=> {
return res.result.reduce((acc: any, cur: Customer) => {
acc[cur.systemNumber] = cur;
return acc;
}, {});
});
After the above code runs, I get one object with one property, that is undefined and its value is the last customer in the collection }
Upvotes: 0
Views: 56