Prism · Sugar

$flatMap

Maps each element to a list and joins those lists into one. Shorthand for a $flatten over a $map.

The source
{
  folders: [
    { name: 'work', files: ['report.pdf', 'notes.md'] },
    { name: 'personal', files: ['photo.jpg'] },
    {
      name: 'archive',
      files: ['old.txt', 'older.txt', 'oldest.txt'],
    },
  ],
}
The config
{
  $flatMap: {
    over: { $ref: '$.folders' },
    as: 'folder',
    body: { $get: { from: { $var: 'folder' }, path: ['files'] } },
  },
}
What comes out
[
  'report.pdf',
  'notes.md',
  'photo.jpg',
  'old.txt',
  'older.txt',
  'oldest.txt',
]
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.