Javascript定义键值对

var variable = 67;
var map =
{
key 1 : 'string_val',
key 2 : variable,
'key 3': function(){alert('blah')},
'if the key is not a valid variable name, or is reserved, quote it': true
}

alert(map.key 1);
alert(map['key 2']);
map.key 3();
if( map['if the key is not a valid variable name, or is reserved, quote it'])
alert('OK?');

你可能感兴趣的:(JavaScript)