Jump to content

combining objects


redbullmarky

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/45133-combining-objects/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/45133-combining-objects/#findComment-219126
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.