Reputation: 14159
I search Google but found entire functions to get cookie value. Isn't there one line statement to retrieve cookie value in javascript?
Upvotes: 2
Views: 3342
Reputation: 846
You can use the following one liner to convert your cookie to a map and then access whatever parameter you need.
let cookieMap = document.cookie.split(";").map((str)=>str.split("=")).reduce(function(map,curr){map[curr[0]]=curr[1];return map},{})
You can checkout https://stackoverflow.com/a/59994987/7810354 for an explanation of how this works.
Upvotes: 0
Reputation: 188164
You could use a javascript library, e.g. jQuery in addition with a plugin: http://plugins.jquery.com/project/cookie
Demo page: http://stilbuero.de/jquery/cookie/
Upvotes: 1