How to programmatically get a list of users by role in Drupal 8/9

In Drupal 8 and drupal 9, get a list of users related to a particular role by using the following snippet. For example, the role is an editor.
copy-icon

Comments

Authors

Read Next