Joining 2 objects...

Stewe Lundin
Mega Guru

I have lists of objects in my code they represent weeks form the time_card table, i have 2 combineddata from 2 different weeks(time sheet) in order to send them in to our  company's time registration application. 

 

My example code  ;

var obja ={};
var objb ={};

obja[1]={}
obja[1].a = 1
obja[1].b = 2

obja[2]={}
obja[2].a = 11
obja[2].b = 22



objb[3]={}
objb[3].a = 1
objb[3].b = 2

objb[4]={}
objb[4].a = 11
objb[4].b = 22

I want to combind the 2 objects obja and objb in to objc containing 1 - 4
In Java Script I found the method Object.assign() 

But I cant get it to work it looks like the method doesn't work.

 

Am I missing some thing or is there an other method. 
I can combined them by looping them through and adding the data in to the target object but now I'm just looking for a nicer solution.
Mostly for readability 

 

 

 

1 ACCEPTED SOLUTION

Stewe Lundin
Mega Guru

Solved this but a bit ugly 

var obj = {};



obj = populate_obj(seed,ojb)



function populate_obj(seed, imp_obj){
  //do magic stuff and add stuff to my object
  return imp_obj;
}

 

View solution in original post

1 REPLY 1

Stewe Lundin
Mega Guru

Solved this but a bit ugly 

var obj = {};



obj = populate_obj(seed,ojb)



function populate_obj(seed, imp_obj){
  //do magic stuff and add stuff to my object
  return imp_obj;
}