tags:

views:

52

answers:

3

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?

+5  A: 
appointerment.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.

Amber
A: 
appoiterment['appointments']['16'] = '21.05.2010';
Jakub Hampl
This is wrong. I assume you meant `appoiterment['appointments']['16']`?
Sean Kinsey
Yes, that's exactly what I meant, thanks for the correction.
Jakub Hampl
A: 
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'.

vsync