How can I access all values of a multi-value field? I am using Drupal 8 for a project for learning purposes. In my case I want to access to a field which contains multiple values, but I can't find how to do that. For example for a single value field I can access it like this:

kint($variables['node']-&gt;field_name-&gt;value);


But how can I get all the values of field which allows more than one value?
To get all values of a multi-value field:

$node = $variables['node'];
$values = array();
foreach ($node-&gt;field_name-&gt;getValue() as $value) {
  if (!empty($value['value'])) {
    $values[] = $value['value'];
  }
}


OR

$node = $variables['node'];
$values = array();
foreach ($node-&gt;field_name as $item) {
  if (!empty($item-&gt;value)) {
    $values[] = $item-&gt;value;
  }
}