Reading a Cookie value



Write a javascript code to read the cookie value


<html>            
  <head>
    <script>
    
      function ReadCookie()
      {
          var cookies = document.cookie;
          document.write("All stored Cookies: username=Admin" + cookies );
    
          var cookiearray = cookies.split(";");

          for (var i = 0; i<cookiearray.length; i++) 
          {
              var cookie_pair = cookiearray[i].trim();
              var name_value_array = cookie_pair.split("=");

              var name = name_value_array[0];
              var value = name_value_array[1];

              document.write("<br>Name is:" + name + " username and Value is: Admin ");
      
          }
      } 
    </script>
  </head>
<body>

  <p>Click the following button to get the Cookies:</p>
  <input type="button" value="Get Cookie" onclick="ReadCookie()"/>
  
  </body>
</html>

Output: