g-viet / til

Today I learned
6 stars 0 forks source link

Get Cookie by name by regex #101

Open g-viet opened 3 years ago

g-viet commented 3 years ago
function getCookieValue(name) {
  let result = document.cookie.match("(^|[^;]+)\\s*" + name + "\\s*=\\s*([^;]+)")
  return result ? result.pop() : ""
}

https://coderrocketfuel.com/article/how-to-create-read-update-and-delete-cookies-in-javascript