how to get parent tids of a taxonomy term I used this code to get the parent ids , but the result is a huge object .  how do I get the parent id's and term names from the resulting object ?

 $ancestors = \Drupal::service('entity_type.manager')-&gt;getStorage("taxonomy_term")-&gt;loadAllParents($tid);
In $ancestors you'll find an array of the parent terms starting with the term $tid itself:

$ancestors = \Drupal::service('entity_type.manager')-&gt;getStorage("taxonomy_term")-&gt;loadAllParents($tid);
$list = [];
foreach ($ancestors as $term) {
  $list[$term-&gt;id()] = $term-&gt;label();
}