【发布时间】:2012-07-04 06:06:31
【问题描述】:
我有两个 JavaScript 对象:
var attributes1 = {
"type": "text/css",
"rel": "stylesheet",
"href": baseUrl + "Styles/HtmlLibrary.css"
};
var attributes2 = {
"type": "text/css",
"rel": "stylesheet",
"href": baseUrl + "Styles/jquery.contextMenu.css"
};
我有什么方法可以将这两个对象组合成一个具有两个子对象(关联数组)的对象?我想遍历它并每次获取一组属性?
谢谢
【问题讨论】:
-
JS中没有关联数组的概念,这些都是js对象
-
你的意思是像
var attributes = [{...},{...}];?我推荐阅读MDN JavaScript Guide,它应该能让你对JS基础有一个很好的了解。 -
我认为@FelixKling 就在这里。这不完全是合并,OP 似乎在寻求一种将两个对象合并为 1 的方法,这很简单:
[attributes1, attributes2]甚至({library: attributes1, menu: attributes2})
标签: javascript associative-array