You do not need to convert $entity into an array, this would simply work.
$entity->get('field_name')->getValue();
FYI : Using kint() from the devel_kint module will let you know all the available methods that could be used to access the object elements, so comparatively var_dump() is less helpful.
You do not need to convert
$entityinto an array, this would simply work.FYI : Using
kint()from thedevel_kintmodule will let you know all the available methods that could be used to access the object elements, so comparativelyvar_dump()is less helpful.We don't really need to call
get()