Clue Mediator

How to get all cookies using JavaScript

📅January 26, 2022

In this article, we will show you how to get a list of all cookies using JavaScript. In the previous article, we explained cookie" title="Cookie">how to set and get cookies in JavaScript.

Checkout more articles on JavaScript

Use the following function to get a list of all cookies of the browser using JavaScript.

const getAllCookies = () => {
  const pairs = document.cookie.split(";");
  let cookies = {};
  for (let i=0; i<pairs class="length;" i++){="" const="" pair="pairs[i].split("=");" cookies[(pair[0]+'').trim()]="unescape(pair.slice(1).join('='));" }="" return="" cookies;="" <="" pre="">

<p>This function will give you the result in the form of an object.</p>

<p>That’s it for today.<br>Thank you for reading. Happy Coding..!! 🙂</p>
<!-- /wp:html --></pairs>