Suraz Khanal Suraz Khanal - 24 days ago 13
AngularJS Question

How to append object into existing object Angularjs

i have two object one is for just to hold answer of one question and another is final object. like

answer = {"value":"asda","indicator":"good"};
final = {} ;


i want to append answer object to final object like this

final = {{"value":"asda","indicator":"good"},{"value":"sdad","indicator":"worse"}}


How can i do that ?

Answer

You can not directly append object. Instead of this you need to hold object in an array like following.

answer = {"value":"asda","indicator":"good"};
final = [];
newObject = {"value":"sdad","indicator":"worse"};

now you can push both object to array like -

final.push(answer);
final.push(newObject);

Result of this will be -

final = [{"value":"asda","indicator":"good"},{"value":"sdad","indicator":"worse"}];

Hope this will help you.

Comments