{"id":4512,"date":"2020-10-01T11:52:00","date_gmt":"2020-10-01T11:52:00","guid":{"rendered":"https:\/\/www.codexworld.com\/?p=4512"},"modified":"2020-10-01T12:15:42","modified_gmt":"2020-10-01T12:15:42","slug":"store-data-in-cookies-with-javascript","status":"publish","type":"post","link":"https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/","title":{"rendered":"Store Data in Cookies with JavaScript"},"content":{"rendered":"<p>The Cookie is a small text file stored in the user&#8217;s computer, it helps to store user information in the web pages. Generally, the Cookies are used in the server-side script to store information that the server embeds on the user&#8217;s computer. You can also use Cookie in the client-side script without interacting with the server.<\/p>\n<p><b>JavaScript Cookie<\/b> is the best option to store data in the web pages without using a server-side script. You can store, read, update, and delete data without interacting with the server. In this tutorial, we will show you how to use <b>Cookies in JavaScript<\/b> to store and modify information in the web pages (client-side script).<\/p>\n<p>The <b>document.cookie<\/b> property is used to create, read, and delete cookies in JavaScript. <\/p>\n<h2>Create Cookie with JavaScript<\/h2>\n<p>Use the <code>document.cookie<\/code> property to create a cookie using JavaScript.<\/p>\n<pre style=\"color: rgb(110, 107, 94);\"><span class=\"hljs-built_in\" style=\"color: rgb(182, 86, 17);\">document<\/span>.cookie = <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"name=John Doe\"<\/span>;<\/pre>\n<p>By default, the cookie is deleted once the browser is closed. But, you can set an expiry date and time (in UTC time) to make the cookie alive as per your needs.<\/p>\n<pre style=\"color: rgb(110, 107, 94);\"><span class=\"hljs-built_in\" style=\"color: rgb(182, 86, 17);\">document<\/span>.cookie = <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"name=John Doe; expires=Wed, 13 Jan 2021 12:00:00 UTC\"<\/span>;<\/pre>\n<p>By default, the cookie belongs to the current page. But, you can set a path the cookie belongs to.<\/p>\n<pre style=\"color: rgb(110, 107, 94);\"><span class=\"hljs-built_in\" style=\"color: rgb(182, 86, 17);\">document<\/span>.cookie = <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"name=John Doe; expires=Wed, 13 Jan 2021 12:00:00 UTC; path=\/\"<\/span>;<\/pre>\n<h2>Read Cookie with JavaScript<\/h2>\n<p>Cookie value can be retrieved using the <code>document.cookie<\/code> property.<\/p>\n<pre style=\"color: rgb(110, 107, 94);\"><span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> value = <span class=\"hljs-built_in\" style=\"color: rgb(182, 86, 17);\">document<\/span>.cookie;<\/pre>\n<h2>Change Cookie Value with JavaScript<\/h2>\n<p>Cookie value can be changed in the same way it created.<\/p>\n<pre style=\"color: rgb(110, 107, 94);\"><span class=\"hljs-built_in\" style=\"color: rgb(182, 86, 17);\">document<\/span>.cookie = <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"name=Codex World; expires=Wed, 13 Jan 2021 12:00:00 UTC; path=\/\"<\/span>;<\/pre>\n<h2>Delete Cookie with JavaScript<\/h2>\n<p>Set empty value and pass the previous date in the expires parameter to delete a cookie.<\/p>\n<pre style=\"color: rgb(110, 107, 94);\"><span class=\"hljs-built_in\" style=\"color: rgb(182, 86, 17);\">document<\/span>.cookie = <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"name=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=\/;\"<\/span>;<\/pre>\n<p>Now, we will create some custom functions to set, get, and delete cookies in JavaScript. These JavaScript functions will provide a user-friendly way to work with cookies on the web page.<\/p>\n<h2>Set Cookie<\/h2>\n<p>The following <code>setCookie()<\/code> function helps to create a cookie with a specific name and value using JavaScript.<\/p>\n<ul class=\"bullet_disk_list\">\n<li><b>name<\/b> &#8211; The name of the cookie.<\/li>\n<li><b>value<\/b> &#8211; The value of the cookie.<\/li>\n<li><b>exp_days<\/b> &#8211; The cookie expiry time in days.<\/li>\n<\/ul>\n<pre style=\"color: rgb(110, 107, 94);\"><span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">function<\/span> <span class=\"hljs-title\" style=\"color: rgb(102, 132, 225);\">setCookie<\/span>(<span class=\"hljs-params\" style=\"color: rgb(182, 86, 17);\">name,value,exp_days<\/span>) <\/span>{\r\n    <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> d = <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">new<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(182, 86, 17);\">Date<\/span>();\r\n    d.setTime(d.getTime() + (exp_days*<span class=\"hljs-number\" style=\"color: rgb(182, 86, 17);\">24<\/span>*<span class=\"hljs-number\" style=\"color: rgb(182, 86, 17);\">60<\/span>*<span class=\"hljs-number\" style=\"color: rgb(182, 86, 17);\">60<\/span>*<span class=\"hljs-number\" style=\"color: rgb(182, 86, 17);\">1000<\/span>));\r\n    <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> expires = <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"expires=\"<\/span> + d.toGMTString();\r\n    <span class=\"hljs-built_in\" style=\"color: rgb(182, 86, 17);\">document<\/span>.cookie = name + <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"=\"<\/span> + value + <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\";\"<\/span> + expires + <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\";path=\/\"<\/span>;\r\n}<\/pre>\n<p><span class=\"note\">Note that:<\/span> The &#8220;\/&#8221; means that the cookie will be available in the entire website domain.<\/p>\n<p><b>Example Code:<\/b><br \/>\nThe following code is used to set a cookie named <code>username<\/code> with the value <code>CodexWorld<\/code> for 5 days.<\/p>\n<pre style=\"color: rgb(110, 107, 94);\">setCookie(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"username\"<\/span>, <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"CodexWorld\"<\/span>, <span class=\"hljs-number\" style=\"color: rgb(182, 86, 17);\">5<\/span>);<\/pre>\n<h2>Get Cookie<\/h2>\n<p>The following <code>getCookie()<\/code> function helps to retrieve the value of a predefined cookie using JavaScript.<\/p>\n<ul class=\"bullet_disk_list\">\n<li><b>name<\/b> &#8211; The name of the cookie.<\/li>\n<\/ul>\n<pre style=\"color: rgb(110, 107, 94);\"><span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">function<\/span> <span class=\"hljs-title\" style=\"color: rgb(102, 132, 225);\">getCookie<\/span>(<span class=\"hljs-params\" style=\"color: rgb(182, 86, 17);\">name<\/span>) <\/span>{\r\n    <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> cname = name + <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"=\"<\/span>;\r\n    <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> decodedCookie = <span class=\"hljs-built_in\" style=\"color: rgb(182, 86, 17);\">decodeURIComponent<\/span>(<span class=\"hljs-built_in\" style=\"color: rgb(182, 86, 17);\">document<\/span>.cookie);\r\n    <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> ca = decodedCookie.split(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">';'<\/span>);\r\n    <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">for<\/span>(<span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> i = <span class=\"hljs-number\" style=\"color: rgb(182, 86, 17);\">0<\/span>; i &lt; ca.length; i++){\r\n        <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> c = ca[i];\r\n        <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">while<\/span>(c.charAt(<span class=\"hljs-number\" style=\"color: rgb(182, 86, 17);\">0<\/span>) == <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">' '<\/span>){\r\n            c = c.substring(<span class=\"hljs-number\" style=\"color: rgb(182, 86, 17);\">1<\/span>);\r\n        }\r\n        <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">if<\/span>(c.indexOf(cname) == <span class=\"hljs-number\" style=\"color: rgb(182, 86, 17);\">0<\/span>){\r\n            <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">return<\/span> c.substring(cname.length, c.length);\r\n        }\r\n    }\r\n    <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">return<\/span> <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"\"<\/span>;\r\n}<\/pre>\n<p><b>Example Code:<\/b><br \/>\nThe following code is used to get the value of the cookie <code>username<\/code>.<\/p>\n<pre style=\"color: rgb(110, 107, 94);\"><span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> user = getCookie(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"username\"<\/span>);<\/pre>\n<h2>Delete Cookie<\/h2>\n<p>The following <code>deleteCookie()<\/code> function helps to remove cookie using JavaScript.<\/p>\n<ul class=\"bullet_disk_list\">\n<li><b>name<\/b> &#8211; The name of the cookie.<\/li>\n<\/ul>\n<pre style=\"color: rgb(110, 107, 94);\"><span class=\"hljs-function\"><span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">function<\/span> <span class=\"hljs-title\" style=\"color: rgb(102, 132, 225);\">deleteCookie<\/span>(<span class=\"hljs-params\" style=\"color: rgb(182, 86, 17);\">name<\/span>) <\/span>{\r\n    <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> d = <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">new<\/span> <span class=\"hljs-built_in\" style=\"color: rgb(182, 86, 17);\">Date<\/span>();\r\n    d.setTime(d.getTime() - (<span class=\"hljs-number\" style=\"color: rgb(182, 86, 17);\">60<\/span>*<span class=\"hljs-number\" style=\"color: rgb(182, 86, 17);\">60<\/span>*<span class=\"hljs-number\" style=\"color: rgb(182, 86, 17);\">1000<\/span>));\r\n    <span class=\"hljs-keyword\" style=\"color: rgb(184, 84, 212);\">var<\/span> expires = <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"expires=\"<\/span> + d.toGMTString();\r\n    <span class=\"hljs-built_in\" style=\"color: rgb(182, 86, 17);\">document<\/span>.cookie = name + <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"=;\"<\/span> + expires + <span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\";path=\/\"<\/span>;\r\n}<\/pre>\n<p><b>Example Code:<\/b><br \/>\nThe following code is used to remove the cookie <code>username<\/code>.<\/p>\n<pre style=\"color: rgb(110, 107, 94);\">deleteCookie(<span class=\"hljs-string\" style=\"color: rgb(96, 172, 57);\">\"username\"<\/span>);<\/pre>\n<h2>Conclusion<\/h2>\n<p>If you want to store data with Cookies on the web pages, JavaScript cookie will be very useful. You can use our custom functions to manage cookies in JavaScript. Also, our example code can be used to store data in the cookie and get\/update\/delete cookies with JavaScript.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Cookie is a small text file stored in the user&#8217;s computer, it helps to store user information in the web pages. Generally, the Cookies are used in the server-side script to store information that <\/p>\n","protected":false},"author":1,"featured_media":4514,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[10],"tags":[342,66],"class_list":["post-4512","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-cookie","tag-javascript","cat-10-id","has_thumb"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Store Data in Cookies with JavaScript - CodexWorld<\/title>\n<meta name=\"description\" content=\"JavaScript Cookies - Store data in the cookie using JavaScript. Create, read, change, and delete cookies with JavaScript. Example code to get, set, and remove the cookie in JavaScript.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Store Data in Cookies with JavaScript - CodexWorld\" \/>\n<meta property=\"og:description\" content=\"JavaScript Cookies - Store data in the cookie using JavaScript. Create, read, change, and delete cookies with JavaScript. Example code to get, set, and remove the cookie in JavaScript.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/\" \/>\n<meta property=\"og:site_name\" content=\"CodexWorld\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codexworld\" \/>\n<meta property=\"article:published_time\" content=\"2020-10-01T11:52:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-10-01T12:15:42+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.codexworld.com\/wp-content\/uploads\/2020\/09\/store-data-in-cookies-with-javascript-codexworld.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1366\" \/>\n\t<meta property=\"og:image:height\" content=\"768\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"CodexWorld\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codexworldblog\" \/>\n<meta name=\"twitter:site\" content=\"@codexworldweb\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"CodexWorld\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/store-data-in-cookies-with-javascript\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/store-data-in-cookies-with-javascript\\\/\"},\"author\":{\"name\":\"CodexWorld\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\"},\"headline\":\"Store Data in Cookies with JavaScript\",\"datePublished\":\"2020-10-01T11:52:00+00:00\",\"dateModified\":\"2020-10-01T12:15:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/store-data-in-cookies-with-javascript\\\/\"},\"wordCount\":465,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/store-data-in-cookies-with-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2020\\\/09\\\/store-data-in-cookies-with-javascript-codexworld.png\",\"keywords\":[\"Cookie\",\"JavaScript\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/store-data-in-cookies-with-javascript\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/store-data-in-cookies-with-javascript\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/store-data-in-cookies-with-javascript\\\/\",\"name\":\"Store Data in Cookies with JavaScript - CodexWorld\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/store-data-in-cookies-with-javascript\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/store-data-in-cookies-with-javascript\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2020\\\/09\\\/store-data-in-cookies-with-javascript-codexworld.png\",\"datePublished\":\"2020-10-01T11:52:00+00:00\",\"dateModified\":\"2020-10-01T12:15:42+00:00\",\"description\":\"JavaScript Cookies - Store data in the cookie using JavaScript. Create, read, change, and delete cookies with JavaScript. Example code to get, set, and remove the cookie in JavaScript.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/store-data-in-cookies-with-javascript\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.codexworld.com\\\/store-data-in-cookies-with-javascript\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/store-data-in-cookies-with-javascript\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2020\\\/09\\\/store-data-in-cookies-with-javascript-codexworld.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2020\\\/09\\\/store-data-in-cookies-with-javascript-codexworld.png\",\"width\":1366,\"height\":768,\"caption\":\"store-data-in-cookies-with-javascript-codexworld\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/store-data-in-cookies-with-javascript\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.codexworld.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Store Data in Cookies with JavaScript\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#website\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"name\":\"CodexWorld\",\"description\":\"Web &amp; Mobile App Development Company\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.codexworld.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#organization\",\"name\":\"CodexWorld\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.codexworld.com\\\/wp-content\\\/uploads\\\/2014\\\/09\\\/codexworld-logo.png\",\"width\":200,\"height\":19,\"caption\":\"CodexWorld\"},\"image\":{\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldweb\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/codexworld\",\"https:\\\/\\\/www.youtube.com\\\/codexworld\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.codexworld.com\\\/#\\\/schema\\\/person\\\/9da51d8fa3cdefeb5ec9c69136d4baf0\",\"name\":\"CodexWorld\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g\",\"caption\":\"CodexWorld\"},\"description\":\"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.\",\"sameAs\":[\"http:\\\/\\\/www.codexworld.com\",\"https:\\\/\\\/www.facebook.com\\\/codexworld\",\"https:\\\/\\\/x.com\\\/codexworldblog\"],\"url\":\"https:\\\/\\\/www.codexworld.com\\\/author\\\/nitya192265\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Store Data in Cookies with JavaScript - CodexWorld","description":"JavaScript Cookies - Store data in the cookie using JavaScript. Create, read, change, and delete cookies with JavaScript. Example code to get, set, and remove the cookie in JavaScript.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/","og_locale":"en_US","og_type":"article","og_title":"Store Data in Cookies with JavaScript - CodexWorld","og_description":"JavaScript Cookies - Store data in the cookie using JavaScript. Create, read, change, and delete cookies with JavaScript. Example code to get, set, and remove the cookie in JavaScript.","og_url":"https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/","og_site_name":"CodexWorld","article_publisher":"https:\/\/www.facebook.com\/codexworld","article_author":"https:\/\/www.facebook.com\/codexworld","article_published_time":"2020-10-01T11:52:00+00:00","article_modified_time":"2020-10-01T12:15:42+00:00","og_image":[{"width":1366,"height":768,"url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2020\/09\/store-data-in-cookies-with-javascript-codexworld.png","type":"image\/png"}],"author":"CodexWorld","twitter_card":"summary_large_image","twitter_creator":"@codexworldblog","twitter_site":"@codexworldweb","twitter_misc":{"Written by":"CodexWorld","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/#article","isPartOf":{"@id":"https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/"},"author":{"name":"CodexWorld","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0"},"headline":"Store Data in Cookies with JavaScript","datePublished":"2020-10-01T11:52:00+00:00","dateModified":"2020-10-01T12:15:42+00:00","mainEntityOfPage":{"@id":"https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/"},"wordCount":465,"commentCount":0,"publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"image":{"@id":"https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2020\/09\/store-data-in-cookies-with-javascript-codexworld.png","keywords":["Cookie","JavaScript"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/","url":"https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/","name":"Store Data in Cookies with JavaScript - CodexWorld","isPartOf":{"@id":"https:\/\/www.codexworld.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/#primaryimage"},"image":{"@id":"https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/#primaryimage"},"thumbnailUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2020\/09\/store-data-in-cookies-with-javascript-codexworld.png","datePublished":"2020-10-01T11:52:00+00:00","dateModified":"2020-10-01T12:15:42+00:00","description":"JavaScript Cookies - Store data in the cookie using JavaScript. Create, read, change, and delete cookies with JavaScript. Example code to get, set, and remove the cookie in JavaScript.","breadcrumb":{"@id":"https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/#primaryimage","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2020\/09\/store-data-in-cookies-with-javascript-codexworld.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2020\/09\/store-data-in-cookies-with-javascript-codexworld.png","width":1366,"height":768,"caption":"store-data-in-cookies-with-javascript-codexworld"},{"@type":"BreadcrumbList","@id":"https:\/\/www.codexworld.com\/store-data-in-cookies-with-javascript\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.codexworld.com\/"},{"@type":"ListItem","position":2,"name":"Store Data in Cookies with JavaScript"}]},{"@type":"WebSite","@id":"https:\/\/www.codexworld.com\/#website","url":"https:\/\/www.codexworld.com\/","name":"CodexWorld","description":"Web &amp; Mobile App Development Company","publisher":{"@id":"https:\/\/www.codexworld.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.codexworld.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.codexworld.com\/#organization","name":"CodexWorld","url":"https:\/\/www.codexworld.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","contentUrl":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2014\/09\/codexworld-logo.png","width":200,"height":19,"caption":"CodexWorld"},"image":{"@id":"https:\/\/www.codexworld.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldweb","https:\/\/www.linkedin.com\/company\/codexworld","https:\/\/www.youtube.com\/codexworld"]},{"@type":"Person","@id":"https:\/\/www.codexworld.com\/#\/schema\/person\/9da51d8fa3cdefeb5ec9c69136d4baf0","name":"CodexWorld","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cf4999db3b409de559f80677afa01729bb2eeda19be273c254e8b2c22729e386?s=96&r=g","caption":"CodexWorld"},"description":"CodexWorld is a programming blog, one-stop destination for web professionals \u2014 developers, programmers, freelancers, and site owners.","sameAs":["http:\/\/www.codexworld.com","https:\/\/www.facebook.com\/codexworld","https:\/\/x.com\/codexworldblog"],"url":"https:\/\/www.codexworld.com\/author\/nitya192265\/"}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/www.codexworld.com\/wp-content\/uploads\/2020\/09\/store-data-in-cookies-with-javascript-codexworld.png","jetpack_shortlink":"https:\/\/wp.me\/p6bxIh-1aM","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/4512","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/comments?post=4512"}],"version-history":[{"count":1,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/4512\/revisions"}],"predecessor-version":[{"id":4513,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/posts\/4512\/revisions\/4513"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media\/4514"}],"wp:attachment":[{"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/media?parent=4512"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/categories?post=4512"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.codexworld.com\/wp-json\/wp\/v2\/tags?post=4512"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}