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 如何实现键值对
最新推荐文章于 2024-04-17 12:46:23 发布
本文通过一个JavaScript代码示例介绍了如何使用对象字面量创建包含不同数据类型的属性(如字符串、变量、函数和布尔值)的对象。此外,还展示了如何通过属性名包含特殊字符的方式访问这些属性。
323

被折叠的 条评论
为什么被折叠?



