Druoal 8 Get nodes from a query

$query = \Drupal::entityQuery('node')
  ->condition('type', 'article'),
  ->condition('field_foo', 'bar');
$nids = $query->execute();
$nodes = $node_storage->loadMultiple($nids);
 
foreach ($nodes as $n) {
  echo $n->title->value; // "titles"
  // do whatever you would do with a node object (set fields, save, etc.)
  $n->set('title', "Test Title");
  $n->save();
}