Array receiving two objects

1

I have two objects and I wanted to create an array this way = >

[{"loj_codigo":2,"loj_fantasia":"teste 1"},{"loj_codigo":1,"loj_fantasia":"teste 2";}]}

I'm getting the following objects = >

Object {1: "1", 2: "2"}
Object {1: "teste 1", 2: "teste 2"}
    
asked by anonymous 13.07.2016 / 04:00

1 answer

1

As far as I understand, this should resolve your issue.

var obj1 = {1:"1", 2:"2"};
var obj2 = {1:"teste 1", 2:"teste 2"};
var arr  = [];

for( i in obj1 ){
    arr.push( JSON.parse('{"loj_codigo":'+i+',"loj_fantasia":"'+obj2[i]+'"}') );
}
    
13.07.2016 / 16:56