Hopefully I can articulate this.
The idea is that I need to combine several google docs into one document. I need to do this by location.
I have a sheet that includes the location and document id that I pulled into an object array (needBatches) and then grouped by the criteria (location):
const grouped = groupBy(needBatches, 'location');
function groupBy(objectArray, property) {
return objectArray.reduce(function (acc, obj) {
const key = obj[property];
if (!acc[key]) {
acc[key] = [];
}
acc[key].push(obj);
return acc;
}, {});
}
Now I want to grab the document Ids stored in each array, so I try to do a forEach but get a type error: "Cannot find function forEach in object".
So I iterate the array like this:
const arr = Object.keys(grouped).forEach(function(e) {
console.log(e, grouped[e])
});
According to the console log it now looks like this:
Location1 [{documentLink1=<link>, documentId1=<id>, folder1=<folder>},{documentLink2=<link>, documentId2=<id>, folder2=<folder>}]
Location2 [{documentLink1=<link>, documentId1=<id>, folder1=<folder>},{documentLink2=<link>, documentId2=<id>, folder2=<folder>}]
It gives me everything on each row, but I really only want the document Id but I can't figure out how to call it in this format.
I've tried:
grouped[e].documentId
grouped[e]["documentId"]
I've just started working with object arrays so my knowledge is pretty limited. Can anyone assist me?
the grouped object looks like this:
Here I'm bringing in only the rows that don't have a document:
const needBatches = dataRange.filter(function(e){
return e.documentLink !== ''
})