view raw
kohli kohli - 6 months ago 33
JSON Question

Json array appending a object

i have pushed data to an array like this{'data': 'type',
'value': 'apple'}

and i want to append the value of that particular array's value object. I tried to do it like this[index].value.push = 'banana';

but it doesn't work?? I want to replace the value


Adding items to arrays work like this in javascript:{'data': 'type', 'value': 'apple'});

However, given that your data is an object, you don't need to use push:[index].value = 'banana';

You can access a value from a javascript object directly.

Given that you have used string keys, you will probably have to do the following:[index]['value'] = 'banana';

Look at this for more info: