First, go to Settings > Privacy > Analytics & Improvements.
Once you're here, see if Share iPhone Analytics (or Share iPhone & Watch Analytics) is enabled. If it isn't, you'll need to enable it and come back to this page in a few days. If it is enabled -- and it is by default -- you're good to go.
Tap on Analytics Data, and then scroll down to find an entry that starts log-aggregated. If there are multiple entries, choose the last one in the list (which will be the latest - check the data on the file) and tap to open.
You now need to copy the data out of the file. I do this by tapping on the screen and dragging the select cursors to grab all the text. This is usually the hardest part of doing this.
Once you've copied the text, open up Notes, create a new note, and paste the contents of the file you copied into the note.
Tap on the three dots at the top of the note and use Find in Note to search for batterycyclecount. This will take you down to the entry, and the number here corresponds to the number of recharge cycles the battery has been through and gives you a good measure of the state of the battery.
This is a really handy trick to find out how much life there is left in the battery of any second-hand iPhone you might be interested in buying.
To find out more about battery cycle counts, read this.