이름별로 모든 쿠키를 나열하려면 배열의 쿠키 쌍을 사용하십시오. 그런 다음 이 배열에서 키 값 쌍을 가져와야 합니다.
예시
다음 코드를 실행하여 모든 쿠키를 나열할 수 있습니다.
라이브 데모
<html>
<head>
<script>
<!--
function ReadCookie() {
var allcookies = document.cookie;
document.write ("All Cookies : " + allcookies );
// Get all the cookies pairs in an array
cookiearray = allcookies.split(';');
// Now take key value pair out of this array
for(var i = 0; i < cookiearray.length; i++) {
name = cookiearray[i].split('=')[0];
value = cookiearray[i].split('=')[1];
document.write ("Key is : " + name + " and Value is : " + value);
}
}
//-->
</script>
</head>
<body>
<form name = "myform" action = "">
<p> click the following button and see the result: </p>
<input type = "button" value = "Get Cookie" onclick = "ReadCookie()"/>
</form>
</body>
</html>