How do I get each taxonomy term associated to a node?
Don’t convert the node to an array, use the node object itself. Then methods will work.

// top of file...
use Drupal\node\NodeInterface;

function custom_preprocess_html(&amp;$variables) {
  $node = \Drupal::routeMatch()-&gt;getParameter('node');

  if ($node instanceof NodeInterface) {
    $type = $node-&gt;getType();
    $id = $node-&gt;id();
    $terms = $node-&gt;get('field_yourfield')-&gt;referencedEntities();
    // code here for $terms...

    $body_classes[] = 'node-' . $id;
    $body_classes[] = $type;
    // ... etc ...
  }
}


I assume type is node type.. but this is where you want to be. $terms should be a list of Term objects, so you can iterate and grab whatever data you need.

You should also check that the node type is the correct one before doing anything as well as checking for existence of the field to avoid errors.