<!DOCTYPE html>
<html lang="en-US">
<body>
<script>
var name = "Steve";
var uName = "";
//Cookie write
document.cookie = "username="+name+";path=/";
// Cookie read all
allcookie=(document.cookie);
// Convert string to array
cookiearray = allcookie.split(";");
// Run through array
cookiearray.forEach(function(element) {
if(element.indexOf("username")>-1)
uName=element.slice((element.indexOf("username=")+9), element.length);
});
// Print the username
document.write(uName);
</script> </body>
</html>