drupal 9 get field value

To get the value of a field in Drupal 9, you can use the getValue() method. Here's an example of how to do it:

$entity = \Drupal::entityTypeManager()->getStorage('entity_type')->load($entity_id);
$field_value = $entity->get('field_name')->getValue();

Replace 'entity_type' with the entity type you are working with (e.g., 'node' for a content type) and 'field_name' with the machine name of the field you want to retrieve the value from.

Please note that this code assumes you have the necessary entity ID and that you have already loaded the entity using the entity type manager.