How do I clear dirt from an inventory slot?

I want to clear dirt from a particular inventory slot.

For example, I want dirt to be cleared only from the 6th slot and not from the other slots. How do I do that?


Solution 1:

Run:

/replaceitem entity @p slot.hotbar 5 air

That will replace the 6th hotbar slot to be air. Unfortunately you cannot check if that slot specifically is dirt.