kohli kohli - 1 year ago 90
JSON Question

Json array appending a object

i have pushed data to an array like this

this.data.push{'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

this.data[index].value.push = 'banana';

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

Answer Source

Adding items to arrays work like this in javascript:

this.data.push({'data': 'type', 'value': 'apple'});

However, given that your data is an object, you don't need to use push:

this.data[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:

this.data[index]['value'] = 'banana';

Look at this for more info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download