Skip to content
Advertisement

Merging contents of an array based on matching content

I am writing some Google Apps Script to get each Google Group and list it’s members then output it to a Google Sheet. Currently, I am grabbing each group and email address and pushing it to the memberArr, however I then want to ‘merge’ the relevant information.

So if for example, I have X Groups and Group 1 has 4 members (Foo, Bar, Baz and Quux) – Currently, it will output as

JavaScript

But I want to have it output as [Group 1, Foo, Bar, Baz, Quux].
That is to say, merge the contents of the memberArr where there is a common Group

Here is my code so far:

JavaScript

Any help would be greatly appreciated!

Edit: Updated to show the memberArr as is rather than in a table format.

Advertisement

Answer

I’d propose to convert the array in the object and then back to the array this way:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement