10 examples of 'document cookie split' in JavaScript

Every line of 'document cookie split' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
9function getCookie(key) {
10 const value = `; ${document.cookie}`
11 const parts = value.split(`; ${key}=`)
12 if (parts.length === 2) return parts.pop().split(';').shift()
13}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

194export function getCookieKeyAndValue(cookieRaw) {
195 const semicolonIndex = cookieRaw.indexOf(';')
196 if (semicolonIndex >= 0) {
197 cookieRaw = cookieRaw.slice(0, semicolonIndex)
198 }
199 return cookieRaw.trim().split('=')
200}
1function getCookie(name) {
2 var value = "; " + document.cookie;
3 var parts = value.split("; " + name + "=");
4 if (parts.length == 2) return parts.pop().split(";").shift();
5}
665function getCookie(name) {
666 var value = "; " + document.cookie;
667 var parts = value.split("; " + name + "=");
668 if (parts.length == 2) return parts.pop().split(";").shift();
669}
5function getCookie(name) {
6 var value = "; " + document.cookie;
7 var parts = value.split("; " + name + "=");
8 if (parts.length == 2) return parts.pop().split(";").shift();
9}
75function getCookie(name) {
76 var value = "; " + document.cookie;
77 var parts = value.split("; " + name + "=");
78 if (parts.length == 2) return parts.pop().split(";").shift();
79}
10function getCookie(name) {
11 var nameEQ = name + "=";
12 var ca = document.cookie.split(';');
13 for(var i=0;i < ca.length;i++) {
14 var c = ca[i];
15 while (c.charAt(0)==' ') c = c.substring(1,c.length);
16 if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
17 }
18 return null;
19
20
21}
283function cookie(key) {
284 // read
285 var decode = function(s) {return decodeURIComponent(s.replace(/\+/g, ' '));}
286 var converted = function(s) {
287 if (s.indexOf('"') === 0) {
288 s = s.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
289 }
290 return s;
291 }
292 var cookies = document.cookie.split('; ');
293 var result = key ? undefined : {};
294 for (var i = 0, l = cookies.length; i < l; i++) {
295 var parts = cookies[i].split('=');
296 var name = decode(parts.shift());
297 var cookie = decode(parts.join('='));
298 if (key && key === name) {
299 result = converted(cookie);
300 break;
301 }
302 if (!key && parts.length) {
303 result[name] = converted(cookie);
304 }
305 }
306 return result;
307};
13function getCookie(name) {
14 var ck = document.cookie;
15 if (ck.length > 0) {
16 var arr = ck.split(';');
17 for(var i=0, len=arr.length; i<len; i++) {
18 if (arr[i].indexOf(name) != -1) {
19 return unescape(arr[i].split('=')[1]);
20 };
21 }
22 };
23 return '';
24}
1function getCookie(name) {
2 var cookieValue = null;
3 if (document.cookie && document.cookie != '') {
4 var cookies = document.cookie.split(';');
5 for (var i = 0; i < cookies.length; i++) {
6 var cookie = yawdadmin.jQuery.trim(cookies[i]);
7 // Does this cookie string begin with the name we want?
8 if (cookie.substring(0, name.length + 1) == (name + '=')) {
9 cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
10 break;
11 }
12 }
13 }
14 return cookieValue;
15}

Related snippets