If looking at a JK, the best years are 2015-2017.
2012-2013 have potential cylinder head issues that are very costly to repair and all of them are out of warranty now. Jeep extended the cylinder head warranty to 10 years/150k miles. The cylinder head issue has also appeared on a few 2014s.
Late 2013 - 2014 had an issue with the oil cooler that could potentially crack and dump all your oil down the back of the engine in seconds. The oil cooler was redesigned in 2013 to make it compatible with the smaller 3.2 Pentastar that was used in the Cherokee. Finally resolved after the 6th or 7th revision for the 2015 model year.
2018 JK had an issue with the solenoid pack in the transmission valve body that would cause a no start problem. Fix was replacing the solenoid pack.
ALL years of the JK have the potential issue of casting sand in the cooling system. I bought a new 2017 and it had a layer of sludge in the coolant reservoir at 10k miles.
I don't know if they ever fixed the 6 speed manual popping out of gear issue.
The 5 speed automatic in them is a good transmission, excepting the 2018 problem.
Plenty of people have no issues with their JK, and there are also plenty of people that do.
Do your research and inspect potential purchases carefully.