I have a response header of set-cookie with the value of set-cookie: frontend=2j5mfe8nidhhmltlaoliu5bmj6; expires=Thu, 10-Sep-2020 22:52:25 GMT; Max-Age=86400; path=/; domain=www.shoepalace.com; httponly and I want to log just the part of the cookie after frontend= up to the ; (That would be 2j5mfe8nidhhmltlaoliu5bmj6)
const string = response.headers['set-cookie'] console.log(string) That logs this: [ 'frontend=0uhi7fj03fro4f5n2at4ev1t77; expires=Fri, 11-Sep-2020 01:15:47 GMT; Max-Age=86400; path=/; domain=www.shoepalace.com; HttpOnly', '__cf_bm=2d7abb53a603ff50426362615a2cba7c3bd0d58c-1599700547-1800-AVURmHeYokYbppItftnydR/xiAuOS75aQzUlJoxN/79VKKgYr9d7cx6DmgdSK4BbvjQ/pjC0+5lQXkLdn/QIdII=; path=/; expires=Thu, 10-Sep-20 01:45:47 GMT; domain=.shoepalace.com; HttpOnly; Secure; SameSite=None' ] const pairs = string.split(';') const obj = {} pairs.forEach(pair => { const split = pair.split('=') const key = split[0] const value = split[1] obj[key] = value }) console.log(obj.frontend)