how to add .js programatically when in an entity list
The correct approach is doing it using a custom list builder, assuming you are using that and not a view.

class MyListBuilder extends EntityListBuilder {

  public function render() {
    $build = parent::render();
    $build['#attached']['library'][] = 'yourmodule/library';
  }
}


Then specify it in the annotation of your entity type.see Node/User or so on how to do that, most entity types specify either the default or a custom list builder.

If it's a view then you can implement one of the many views hooks, if it's not your own entity type then I'm not exactly sure why you need to add a JS there and you should explain in more detail what kind of list it is and what your JS does.