How to display a list of nodes in a block? I have a custom block and I want to output a list of nodes of a certain type. 

This is what I have so far:

public function build() {

$nids = \Drupal::entityQuery('node')
  -&gt;condition('type', 'my_content_type')
  -&gt;execute();

$nodes = \Drupal::entityTypeManager()
  -&gt;getStorage('node')
  -&gt;loadMultiple($nids);

    return array(
      '#markup' =&gt; $this-&gt;t('How to display list here'),
    );
  }
}


How do I list the nodes by title and ordered by newest at the bottom of list?
Unless you have a specific issue not mentioned in the question, I would recommend using a view to create this block. This would mean that the criteria remained easily editable.

If you had specific need to output the list of nodes within a custom block, or would like to pass arguments to the view from custom code you could use views_embed_view.