Reference:
Twig : Unset element from array - Stack Overflow
Simple Example:
{% if link.attributes is defined %}
{# we want to get rid of the attributes element #}
{% set link = link|filter((v, k) => k != 'attributes') %}
{% endif %}
Nested Example:
{% if link.attributes.class is defined %}
{# we want to get rid of the class element inside the attributes #}
{% set link =
link|merge({
attributes: link.attributes | filter((v, k) => k != 'class')
})
%}
{% endif %}