How to delete a node programmatically in drupal 10

use Drupal\node\Entity\Node;

$node = \Drupal::routeMatch()->getParameter('node');

// Here article is the node type.
$nids = \Drupal::entityQuery('node')
  ->condition('type', 'article')
  ->accessCheck(TRUE)
  ->execute();

// Get the list of nodes 
$nodes = Node::loadMultiple($nids);

// You can use the delete function of the node
foreach($nodes as $node) {
  $node->delete();
}    

Category