Q:

Write a JavaScript program to parse an HTTP Cookie header string and return an object of all cookie name-value pairs

0

Write a JavaScript program to parse an HTTP Cookie header string and return an object of all cookie name-value pairs.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

const parseCookie = str =>
  str
    .split(';')
    .map(v => v.split('='))
    .reduce((acc, v) => {
      acc[decodeURIComponent(v[0].trim())] = decodeURIComponent(v[1].trim());
      return acc;
    }, {});
console.log(parseCookie('foo=bar; equation=E%3Dmc%5E2'));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now