Of course I know that if I press F key, offhand and mainhand's item swaps. But I want to do this with command.
I tried:
execute as @a[nbt={Inventory:[{id:"minecraft:snowball",Slot:-106b}]}] at @s run tag @s add snowball
execute as @a[tag=snowball] at @s run item replace entity @s weapon.mainhand from entity @s weapon.offhand
execute as @a[tag=snowball] at @s run item replace entity @s weapon.offhand from entity @s weapon.mainhand
But I don't think this is possible.