admin管理员组文章数量:1429466
How to create an associative javascript/jquery array of this php structure:
$array = array(
'index' => array(
'subindex' => 'default',
'subindex' => 'default'
),
'index2' => array(
'subindex2' => 'default',
'subindex2' => 'default'
)
);
Thanks!
How to create an associative javascript/jquery array of this php structure:
$array = array(
'index' => array(
'subindex' => 'default',
'subindex' => 'default'
),
'index2' => array(
'subindex2' => 'default',
'subindex2' => 'default'
)
);
Thanks!
Share Improve this question asked Jan 28, 2012 at 15:23 user558134user558134 1,1296 gold badges26 silver badges38 bronze badges 1-
Javascript does not have associative arrays. It has objects, which can have properties accessible like this:
obj['propName']
, which kind of makes it look like an associative array....but it's not really an array. – Jonathan Commented Jan 28, 2012 at 15:34
3 Answers
Reset to default 5var a = {
'index': {
'subindex1': 'default',
'subindex2': 'default'
},
'index2': {
'subindex1': 'default',
'subindex2': 'default'
}
};
JSON Encode
echo json_encode($array);
like this
<script type="text/javascript">
var anArray = [
{"index":[
{"subindex":"default"},
{"subindex":"default"}
]},
{"index2":[
{"subindex":"default"},
{"subindex2":"default"}
]}
];
</script>
本文标签: Jquery javascript associative arrayStack Overflow
版权声明:本文标题:Jquery javascript associative array - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745504410a2661179.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论