Answer In the browser cookies is store in string format containing key-value pairs. So, how to parse a browser Cookie string and return an object of all cookie name-value pairs? separate each key-value pair using String.prototype.split(';') Use Array.prototype.map() and String.prototype.split('=') to separate keys from values in each pair. Use Array.prototype.reduce() and decodeURIComponent() to create an object with all key-value pairs. const parseCookie = str => str .split(';') .map(v => v.split('=')) .reduce((acc, v) => { acc[decodeURIComponent(v[0].trim())] = decodeURIComponent(v[1].trim()); return acc; }, {}); // cookie in browser: `pkg=math; equation=E%3Dmc%5E2` parseCookie(document.cookie); //console: { pkg: 'math', equation: 'E=mc^2' } Share this:TwitterFacebookRedditLinkedInWhatsAppPrintTumblr Related