Connect 2017 iMac to an HDMI tv?

What cable do I need for that? I've seen different things in different places, never specifically for the 2017 iMac with the following specs:

  • 2017 27" iMac Retina 5K
  • 24GB RAM
  • Radeon Pro 580 8GB
  • macOS Catalina 10.15.4

You need a Thunderbolt 3 to HDMI converter. Your iMac has two Thunderbolt 3 (with the USB-C form factor). This converter is available from Apple. Make sure to buy the Thunderbolt3 to HDMI converter, and not Thunderbolt-2 to HDMI, as Thunderbolt3 uses USB-C, and Thunderbolt2 uses miniDisplayPort

My source for the information about your iMac: EveryMac.com - Apple iMac 27-Inch "Core i5" 3.8 (5K, Mid-2017) Specs

You should be able to get 4k output if your television is capable of that resolution (3840x2160). In other words, you will get no higher than your television's resolution.