Combine values from the same key for each object in an array

I have some data like this, which is part of a larger object (and are many objects like this):
    "departments": [
      {
        "id": 10111,
        "name": "Sales",
      },
           {
        "id": 10115,
        "name": "Super Sales",
      }
    ],

And I would like to output:
“departments”=“Sales, Super Sales”

I can split out each child of the departments in the array into 2 separate items using

return items[0].json.departments.map(item => ( { json : item } ));

But I am only interested in departments.name

In the example there are only 2 departments but looking for a solution that will work for an number of departments (but usually between 1 and 3).

use function item

return item.departments.map(d=>d.name).join(',')
3 Likes

Thanks for your help here matte but it’s putting each character as an object in an array.

I’d then like to filter out duplicates. How can I clean up the data to be able to work on it in other nodes?