0

I have two arrays and I want to add both. Is it possible to get this:

var frist = {
    "2162018": [
        {
            st_id: "18ds1",
            status: "A",
            today_milli: 1529570651.113
        },
        {
            st_id: "18ds1",
            status: "A",
            today_milli: 1529570827.709
        }
    ]
};
var second = {
    "2362018": [
        {
            st_id: "18ds1",
            status: "A",
            today_milli: 1529574243.613
        }
    ]
};
//and i want my final data array like this 
var final_data = {
    "2162018": [
        {
            st_id: "18ds1",
            status: "A",
            today_milli: 1529570651.113
        },
        {
            st_id: "18ds1",
            status: "A",
            today_milli: 1529570827.709
        }
    ],
    "2362018": [
        {
            st_id: "18ds1",
            status: "A",
            today_milli: 1529574243.613
        }
    ]
};

1 Answer 1

1

var frist =  
{ '2162018': 
    [
      { st_id: '18ds1', status: 'A', today_milli: 1529570651.113 },
      { st_id: '18ds1', status: 'A', today_milli: 1529570827.709 }
    ]
 }

 var second = 
 { '2362018': 
   [ 
     { st_id: '18ds1', status: 'A', today_milli: 1529574243.613 } 
   ] 
 }

let final_data = {...frist,...second}
console.log(final_data)

Yes you can simply using spread syntax to combine and construct new object

Sign up to request clarification or add additional context in comments.

2 Comments

thanks bro it works. this problem wasted my all day :-(
You can mark it as answer as reference for other people who face the similar problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.