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'.