Converting fetch’s response headers to a plain serializable JavaScript object

fetch’s response is an object that has a headers property. But this property is of type Headers which is not serializable.

Here’s a little function that convert response headers into a simple JavaScript object ready to be serialized or printed to the console.

Update: the code is updated in 2020–06–01 using Object.fromEntries(). Thanks Matthias Etienne for the awesome tip in the comment.

Knowledge Worker, MSc Systems Engineering, Tech Lead, Web Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store