I have tried many things like apple cider vinegar and dish soap and they all work well!!! However, I have found the best thing they are attracted to is a SOUR BEER!!!!!! Leave some out in a low cup and see them swarm! You might want to use plastic wrap with poked holes on top too to trap them.
If they're in your house, they are sometimes fungus gnats in your plants. Let the soil dry out - they lay eggs in damp soil.
The age old challenge. You didn't clarify where you want to get rid of the gnats. Inside or outside? House, patio, or ??? Some people swear by Avon Skin So Soft for personal protection. Nets over the head with long sleeves and pants help too. Check the internet for suggestions to get rid of gnats for your situation. Here is one site to start a search.: https://www.wikihow.com/Get-Rid-of-Gnats
If you have gnats in your house, put out a shallow bowl of red wine vinegar, cover with plastic wrap and poke holes in the wrap.... Place on your counter and they will congregate in the vinegar......good luck!
I will try this