遍历映射表

对象可以用来当做映射表,将名称和值关联起来。
可以使用in运算符确定对象中是否包含特定名称的属性。
可以在for循环中(for (var name in object))使用关键字 in 来遍历对象中包含的属性。

1
2
3
4
for (var eventinmap) 
console.log("The correlation for' "+ event +" 'is"+ map[event]);
//→ The correlation for 'pizza' is 0.069
//→ The correlation for 'touch tree' is -0.081

映射表内容

1
2
3
4
5
6
7
8
9
10
11
var map = {} ;
function storePhi(event , phi){
map[event] = phi;
}

storePhi("pizza",0.069);
storePhi("touch tree",-0.081);
console.log("pizza" in map);
//→ true
console.log(map["touch tree"]);
//→ -0.081