I have two objects:
var arr= [ 0: { selectedAns: "test answer 1", id: "28", status: "answered" } ] and:
var answerList = [ 0: { selectedAns: "test answer 2 ques 5", id: "27", status: "answered" }, 1: { selectedAns: "test answer 3 ques 6", id: "29", status: "answered"} ] When I do this:
arr1.push(arr); arr1.push(answerList); I am getting this result:
var arr1=[0:{ 0:{selectedAns: "test answer 2 ques 5", id: "27", status: "answered"} } 1:{ 0:{selectedAns: "test answer 1", id: "28", status: "answered"} 1:{selectedAns: "test answer 3 ques 6", id: "29", status: "answered"} }] But I want something like this:
var arr1=[ 0:{selectedAns: "test answer 2 ques 5", id: "27", status: "answered"} 1:{selectedAns: "test answer 1", id: "28", status: "answered"} 2:{selectedAns: "test answer 3 ques 6", id: "29", status: "answered"} ] What am I doing wrong? Thanks.
Note: I am removing duplicates from objects before merging two objects, even if any key has duplicate value like here in status key. Still, I need to merge both the objects. Per my requirement only the id key needs to be unique, so I need a way to merge the two objects as above.
0:,1:etc syntax shown...none of that is valid syntax. An array of objects looks like[{},{},{}]arrandanswerList. Then you try to address something calledarr1. What is it?