Answers for "get all cookies js"

1

javascript get all cookies

var getCookies = function(){
  var pairs = document.cookie.split(";");
  var cookies = {};
  for (var i=0; i<pairs.length; i++){
    var pair = pairs[i].split("=");
    cookies[(pair[0]+'').trim()] = unescape(pair.slice(1).join('='));
  }
  return cookies;
}

var myCookies = getCookies();
console.log(myCookies);
Posted by: Guest on March-07-2020
-1

get all cookies

let c = document.cookie.split(";").reduce( (ac, cv, i) => Object.assign(ac, {[cv.split('=')[0]]: cv.split('=')[1]}), {});

console.log(c);
Posted by: Guest on September-08-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language