<!DOCTYPE html>
<html lang="en-US">
<body>
<script>
var bike ={
company:"honda",
model:"CBR 1000RR",
color:"Red"
};
var uBike = "";
//Cookie write
document.cookie = "userbike="+JSON.stringify(bike)+";path=/";
//Cookie read all
allcookie=(document.cookie);
//Convert string to array
cookiearray = allcookie.split(";");
//Run through array
cookiearray.forEach(function(element) {
if(element.indexOf("userbike")>-1)
uBike=element.slice((element.indexOf("userbike=")+9), element.length);
});
//Convert string to object
uBike = JSON.parse(uBike);
// Print the name
document.write(uBike.company);
</script> </body>
</html>