How to get rest api pagination headers via fetch

You have to use res.headers.get("X-WP-TotalPages") or res.headers.get("X-WP-Total") to get the header values. See the MDN Fetch documentation’s Headers section.