redbullmarky Posted April 1, 2007 Share Posted April 1, 2007 Hi there Javascript definitely my weak point, so here's my question that may seem obvious to some... If I have two 'objects' that I use to store data, eg: var first = {name:'Mark', age:27} var second = {location:'UK'} what's the easiest way to combine them together so that I have something like: {name:'Mark', age:27, location:'UK'} Cheers Mark Quote Link to comment https://forums.phpfreaks.com/topic/45133-combining-objects/ Share on other sites More sharing options...
tomfmason Posted April 1, 2007 Share Posted April 1, 2007 try something like first.location = second.location; Quote Link to comment https://forums.phpfreaks.com/topic/45133-combining-objects/#findComment-219101 Share on other sites More sharing options...
tomfmason Posted April 1, 2007 Share Posted April 1, 2007 I did some more research on that and found that there is no easy way to combine json objects. If it were an array you could use concat but that will not work in this case. I will work on a function for that.. Quote Link to comment https://forums.phpfreaks.com/topic/45133-combining-objects/#findComment-219121 Share on other sites More sharing options...
redbullmarky Posted April 1, 2007 Author Share Posted April 1, 2007 ahh worked wonders.cheers! if (extraparams) { for (i in extraparams) { params[i] = extraparams[i]; } } however, i did a bit more digging around mootools which i'm using, and found that i can also do: if (extraparams) { Object.extend(params, extraparams); } cheers for the help! Mark Quote Link to comment https://forums.phpfreaks.com/topic/45133-combining-objects/#findComment-219126 Share on other sites More sharing options...
emehrkay Posted April 2, 2007 Share Posted April 2, 2007 I love mootools!!! i was about to suggest that you use it becuase i know of that function Quote Link to comment https://forums.phpfreaks.com/topic/45133-combining-objects/#findComment-219490 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.