javascript - JSON element added not showing -


i using express.js develop api. have json object returned mongoose , need add en element each element in result.docs.

i doing follows:

for(a in result.docs)     {         result.docs[a].links={             "test":'test',             "test": 'test',              "test": 'test'          };      } 

after doing returning result object, links not added. on other hand if write

console.log(result.docs[1].links); 

the object shown properly.

any ideas please?

thanks

possibly you're working mongoose document instance instead of plain object, in case use toobject method plain object, implementation be:

var objs = [];  for(var in result.docs) {    var obj = result.docs[a].toobject();    obj.links = {         "test":'test',         "test": 'test',          "test": 'test'      };           objs.push(obj); }  // objs 

toobject documentation


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -