Connect 2017 iMac to an HDMI tv?
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.