Structure Field: Group entries based on field

Hi There,
I’m trying to make groupings by year using structure field.
My blue print looks like this:

  headlines:
    type: structure
    style: table
    fields:
      headline:
        label: Headline
        type: textarea
      year:
        label: Year
        type: number
        default: 2018

First thing I’m not sure about is the year field type. Couldn’t find if there’s an year field.

The result I’m aiming for would output all entries in groups by year:

2018:
Entry, Entry, Entry

2017:
Entry

2016:
Entry, Entry

2015:
Entry

You can group your structure field entries just like any collection:

$groupedCollection  = $page->headlines()->structure()->groupBy('year');

Then loop through the collection:

foreach($groupedCollection as $year => $itemsPerYear): ?>
    <h2><?php echo $year ?></h2>
    <ul>
      <?php foreach($itemsPerYear as $item) : ?>
      <li><?php echo $item->headline() ?></li>
      <?php endforeach; ?>
    </ul>
<?php endforeach ?>

Works perfect
Thank you tex!