underscore.js - Is it Possible to Use Underscore to Create a Javascript Objects with a Variable? -


i have following situation:

var newobject = {user: object, user1: object1} var user = "something"; var object = {key: [obj, obj], key1: [obj, obj]} 

i'd want add following array of objects in var object:

var addtoit = [obja, objb]; 

in end var object should like:

var object = {key: [obj, obj, obja, objb], key1: [obj, obj]} 

i believe there way underscore until i've not been able figure out. solution or suggestion appreciated!

in effort share approach, here thought work i'm getting error when try push , undefined values key , key1:

var newhistory = _.mapobject(newobject, function(valn, keyn){ _.mapobject(valn, function(vs, ks){ if(ks = key){ return vs.push(addtoit); } }) }) 

try way , see whether 1 works or not

_.mapobject(newobject, function(valn, keyn){          var arr=[];         _.mapobject(valn, function(vs, ks){                 if(ks = "key"){                  arr.push(vs);                  arr.push(addtoit)                 }          });         return arr;     }) 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -