How to loop through field deltas of an object? In Drupal 7 I loaded the node/entity I want with node_load / entity_load and, if necessary, then I took a field with multiple deltas and take the value I wanted with a foreach loop.

In Drupal 8 how can I do the same in a hook?

For example, this loads my first value of a field:

$a_id = $adress-&gt;field_a-&gt;target_id;


In this case an entity reference field.
But there are more target_ids.

So how to take them?
Entity reference fields have a method called referencedEntities().

Usage example:

$addresses = $entity-&gt;get('address');
foreach($addresses-&gt;referencedEntities() as $delta =&gt; $address) {
  // Do something with the $address entity
}


P.S.
If you only want the field then as @Clive mentioned you can just iterate over $addresses.