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 how to set and get cookies in JavaScript.
Checkout more articles on JavaScript
- Detect a mobile device using JavaScript
- Remove a property from an object in JavaScript
- Download a file using JavaScript
- Verify an image URL in JavaScript
- Navigator object in 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>