document.cookie

cookieをsetする

<script>
document.cookie ="key01=value01;";
</script>

複数セット

<script>
document.cookie ="keyA=valueA;";
document.cookie ="keyB=valueB;";
</script>

<script>
var cookieString = document.cookie;

function getCookie(key){
	var cookieString = document.cookie;

	var cookieArray = cookiString.split(";");

	for (var i=0; i<cookieKeyArray.length; i++){
		var targetCookie = cookieKeyArray&#91;i&#93;;

		targetCookie = targetCookie.replace(/^\s+|\s+$/g, "");

		var valueIndex = targetCookie.indexOf("=");
		if(targetCookie.substring(0, valueIndex) == key){
			returnn unescape(targetCookie.slice(valueIndex + 1));
		}
	}
	return "";
}
</script>

cookieを取得して配列にする

<script>
var str = document.cookie;

function getCookieArray(){
	var arr = new Array();
	if(document.cookie != ''){
		var tmp = document.cookie.split('; ');
		for(var i=0; i<tmp.length; i++){
			var data = tmp&#91;i&#93;.split('=');
			arr&#91;data&#91;0&#93;&#93; = decodeURIComponent(data&#91;1&#93;);
		}
	}
	return arr;
}

console.log(getCookieArray());
</script>

わかったような、わかってないような。
passの指定

document.cookie = 'data=123; path=/hoge/';
<script>
var expire = new Date();
expire.setTime(expire.getTime() + 1000 * 3600 * 24);
document.cookie = 'data=123; expires=' + expire.toUTCString();
</script>