“Parse document.cookie” Kode Jawaban

Parse document.cookie

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' }
thuga.exe

JS Parse Cookie String

const parseCookie = str =>
  str
    .split(';')
    .map(v => v.split('='))
    .reduce((acc, v) => {
      acc[decodeURIComponent(v[0].trim())] = decodeURIComponent(v[1].trim());
      return acc;
    }, {});
Alert Angelfish

Jawaban yang mirip dengan “Parse document.cookie”

Pertanyaan yang mirip dengan “Parse document.cookie”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya