admin管理员组文章数量:1425023
Adding key/value into array where value is a object
I want to add some text as a key and Object as a value.
Example
$('#clickme').on('click' , function() {
push to array => "some_text" as (value) and $(this) as key
})
Adding key/value into array where value is a object
I want to add some text as a key and Object as a value.
Example
$('#clickme').on('click' , function() {
push to array => "some_text" as (value) and $(this) as key
})
Share
Improve this question
edited Jun 26, 2012 at 11:17
Sirko
74.1k19 gold badges155 silver badges190 bronze badges
asked Jun 26, 2012 at 11:16
user1184100user1184100
6,90430 gold badges84 silver badges122 bronze badges
4
- you can't have a non numeric key for arrays in javascript – Mukesh Soni Commented Jun 26, 2012 at 11:17
- thank you for the reply, what would be the best approach for this? – user1184100 Commented Jun 26, 2012 at 11:18
- store what you require as object properties – Mukesh Soni Commented Jun 26, 2012 at 11:19
-
Tried
$(this).data(value)
? See api.jquery./data and api.jquery./jQuery.data – Stefan Commented Jun 26, 2012 at 11:21
2 Answers
Reset to default 6Just use a normal object which works as an associative array anyway:
var myObj = {};
$('#clickme').on('click' , function() {
myObj["some_text"] = $(this);
});
This should work:
var myArr = new Array();
myArr["MyKey"] = { name: "myobject" };
本文标签: javascriptAdding keyvalue into array where value is a objectStack Overflow
版权声明:本文标题:javascript - Adding keyvalue into array where value is a object - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745439443a2658379.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论