Get parent menu item of a current node I'm trying to get the parent menu item of node I am currently on:
$node_id = // some id
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
$menu_link = $menu_link_manager-&gt;loadLinksByRoute('entity.node.canonical', array('node' =&gt; $node_id));
$parent = $menu_link-&gt;getParent();

but for some reason it always fails with this error:
Error: Call to a member function getParent() on array

When I inspect $menu_link I can clearly see it is there:

Also the method of getParent() seems to be correct: Docs
Would appreciate any help!
I think you need to reset the collection first, as the ::loadLinksByRoute() annotation states that it returns an array of MenuLinkInterfaces[].
See /core/lib/Drupal/Core/Menu/MenuLinkManagerInterface.php:

  /**
   * Loads multiple plugin instances based on route.
   *
   * @param string $route_name
   *   The route name.
   * @param array $route_parameters
   *   (optional) The route parameters. Defaults to an empty array.
   * @param string $menu_name
   *   (optional) Restricts the found links to just those in the named menu.
   *
   * @return \Drupal\Core\Menu\MenuLinkInterface[]
   *   An array of instances keyed by plugin ID.
   */
  public function loadLinksByRoute($route_name, array $route_parameters = [], $menu_name = NULL);

So do something like:
/** @var \Drupal\Core\Menu\MenuLinkManagerInterface $menu_link_manager */
$menu_link_manager = \Drupal::service('plugin.manager.menu.link');
$menu_links = $menu_link_manager-&gt;loadLinksByRoute('entity.node.canonical', array('node' =&gt; $node_id));
// Reset collection by retrieving the first item.
$menu_link = reset($menu_links);
// Now call the parent method.
$parent = $menu_link-&gt;getParent();