admin管理员组文章数量:1388105
I have a JavaScript object like:
appointerment= {ids: '15,16,17', appointments: {'15': '12.05.2010,14,05,2010'} }
now in appointments object I want to add something like '16': '21.05.2010'
what is the best possible way to do this?
I have a JavaScript object like:
appointerment= {ids: '15,16,17', appointments: {'15': '12.05.2010,14,05,2010'} }
now in appointments object I want to add something like '16': '21.05.2010'
what is the best possible way to do this?
Share Improve this question edited May 12, 2010 at 13:17 Crescent Fresh 117k27 gold badges157 silver badges140 bronze badges asked May 12, 2010 at 11:15 user160820user160820 15.2k22 gold badges71 silver badges95 bronze badges3 Answers
Reset to default 6appointerment.appointments['16'] = '21.05.2010';
JSON is short for "JavaScript Object Notation", and as the name implies, it's basically just a way of representing Javascript objects. Thus, one can interact with JSON in the ways one tends to interact with any other object in Javascript, via the usage of the .
or []
operators.
appoiterment['appointments']['16'] = '21.05.2010';
var x = { a:1, b:{c:1} }
x.b.d = 1
// x is now { a:1, b:{c:1, d:1} }
Note - But this won't work in the case of numbers like '16'.
本文标签: How do I add a new keyvalue pair in existing JavaScript objectStack Overflow
版权声明:本文标题:How do I add a new key:value pair in existing JavaScript object? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744553687a2612340.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论