I'm trying to merge 2 objects into 1 object without changing the order.
For example:
obj1 = {"-":"-","<1":"test"};
obj2 = {"1":"1","2":"2"};
The output that i wanna generate:
obj3 = {"-":"-","<1":"test","1":"1","2":"2"};
I've tried using:
- add & concat => fail, coz it's generates an array of objects
extend => almost, somehow obj1 is put after obj2 so it become like this:
obj3 = {"1":"1","2":"2","-":"-","<1":"test"};
merge without changing obj1 and obj2 into array => fail, it only returns me obj1
result=$.merge( obj1, obj2 );
merge with first changing obj1 and obj2 into array => fail, it became array of objects
A lil enlightenment here? Thanks in advance.
UPDATE:
this is my code:
obj2 = {};
obj1 = {"-":"-","<1":"test"};
for(x = 1;x<=2;x++){
obj2[x] = x;
}
obj3 = $.extend(obj1, obj2);
return obj3;
Apparently, when we print the obj3 in console it prints as:
obj3 = {"1":"1","2":"2","-":"-","<1":"test"};
but actually, when u process the obj3 return in another function, the order remains as in:
{"-":"-","<1":"test","1":"1","2":"2"};
Interesting.... Well problem solved. Thank you! Everyone gets a +1