<script src="https://cdnjs.cloudflare.com/ajax/libs/js-cookie/3.0.1/js.cookie.min.js"></script>
Cookies.set('cookie_name', 'cookie_value', { expires: 365 });
Cookies.get('cookie_name'); // => 'value'
Cookies.remove('cookie_name');
// how to add to cookie
document.cookie = "yourKey=your value"
function getCookie(cookie, name) {
const q = {}
cookie?.replace(/s/g, '')
.split(';')
.map(i=>i.split('='))
.forEach(([key, value]) => {
q[key] = value
})
return q[name]??null;
}
<script type="text/javascript">
function setCookie(key, value, expiry) {
var expires = new Date();
expires.setTime(expires.getTime() + (expiry * 24 * 60 * 60 * 1000));
document.cookie = key + '=' + value + ';expires=' + expires.toUTCString();
}
function getCookie(key) {
var keyValue = document.cookie.match('(^|;) ?' + key + '=([^;]*)(;|$)');
return keyValue ? keyValue[2] : null;
}
function eraseCookie(key) {
var keyValue = getCookie(key);
setCookie(key, keyValue, '-1');
}
</script>
document.cookie = "firstName=Anthony";
cookieData=document.cookie.split("; ");
for(let i=0; i<cookieData.length; i++){
cookieData[i]=cookieData[i].split("=");
cookieName=cookieData[i][0];
cookieValue=cookieData[i][1];
//write your cookie name which you want to see in the place of 'mobNo'
if(cookieName==='mobNo'){
console.log(cookieData[i]);
}
}