Javascript/オブジェクト(連想配列)

解説 キーでアクセス、管理ができる配列
sample1

sample1p

sample1code
var number01 = {
  name: "yamada",
  from: "USA",
  score: 80
};
document.getElementById("sample1p").innerHTML = number01.name + number01.score;
	
sample2
sample2code
var traffic_light = {
  blue: "go",
  yellow: "slow",
  red: "stop",
  current: "",
  change_light: function(){
	switch(traffic_light.current){
	  case traffic_light.blue:
		traffic_light.current = traffic_light.yellow;
	  break;
	  case traffic_light.yellow:
		traffic_light.current = traffic_light.red;
	  break;
	  case traffic_light.red:
		traffic_light.current = traffic_light.blue;
	  break;
	  default :
		traffic_light.current = traffic_light.blue;
	}
  }
}
function s2Func(){
  traffic_light.change_light();
  console.log(traffic_light.current);
}
	
sample3
sample3code
var s3Obj = {
	name: "s3Name",
	func: function(){
		console.log(s3Obj.name);
	}
}
var s3Btn = document.getElementById("s3Btn");
s3Btn.addEventListener("click", s3Obj.func);
	
sample4
s4Div
sample4code
var s4Obj = {"ソヨゴ":"モチノキ科", "山茶花":"ツバキ科", "モッコク":"モッコク科"};
var s4Select = document.getElementById("s4Select");
var s4Div = document.getElementById("s4Div");
s4Select.onchange = function s4Func(){
  s4Div.innerHTML = s4Obj[s4Select.value];
}
sample5
sample5code
function s5Func(){
  var s5Obj = {"ソヨゴ":"モチノキ科", "山茶花":"ツバキ科", "モッコク":"モッコク科"};
  for(key in s5Obj){
	console.log(key + s5Obj[key]);
  }
}
	
sample6
sample6code
var s6Obj = new Object();
s6Obj.func = function(){
	console.log(s6Obj);
};
s6Obj.name = "s6Name";
s6Obj.point = 6;
s6Obj.color = "navy";
	
sample7
sample7code
function s7Func(type, season){
  this.type = type;
  this.season = season;
  this.func = function(){
  	console.log(this.season);
  }
}
var tubaki = new s7Func("常緑樹", "winter");
var tutuji = new s7Func("常緑樹", "spring");
	
sample8
sample8code
function s8Func(){
  var s8Obj = {"常緑樹":"サザンカ", "落葉樹":"イチョウ"}
  var s8Select = document.getElementById("s8Select");
  console.log(s8Obj[s8Select.value]);
}