How to merge array of objects A and B and form array of object C contains new key value pair?











up vote
0
down vote

favorite
1












I am using Node.js for programming,
In the below array of Objects A and B have the arrays with have some duplicates values also, but we have to skip the duplicated for only based on func_id of the arrays. In the array C we have push both A and B func_score values based on func_id and func_score_A from A(func_score) array and func_score_B from B(func_score) array.



Sample Code:



var A = [{
"func_id": 1,
"func_score": 0.4
}, {
"func_id": 2,
"func_score": 0.5
}, {
"func_id": 3,
"func_score": 0.7
}];
var B = [{
"func_id": 3,
"func_score": 0.9
}, {
"func_id": 4,
"func_score": 0.7
}, {
"func_id": 5,
"func_score": 0.8
}];
var C = ;
var tmpArray = ;
A.forEach(function(element) {
B.forEach(function(loop) {
if (element.func_id === loop.func_id) {
var tmpObje = {
func_id: element.func_id,
func_sore_A: element.func_score,
func_sore_B: loop.func_score
}
tmpArray.push(tmpObje);
C.push(tmpObje);
return;
}
});
});

A.forEach(function(element) {
tmpArray.forEach(function(loop) {
if (element.func_id !== loop.func_id) {
var smsObj = {
func_id: element.func_id,
func_sore_A: element.func_score,
func_sore_B: 0
}
C.push(smsObj);
return;
}
});
});

B.forEach(function(element) {
tmpArray.forEach(function(loop) {
if (element.func_id !== loop.func_id) {
var domineObj = {
func_id: element.func_id,
func_sore_A: 0,
func_sore_B: loop.func_score
}
C.push(domineObj);
return;
}
});
});
console.log(C);


Expected Output



[
{"func_id": 1,
"func_score_A": 0.4,
"func_score_B":0
},
{"func_id": 2,
"func_score_A": 0.5,
"func_score_B":0
},
{"func_id": 3,
"func_score_A": 0.7,
"func_score_B":0.9
},
{"func_id": 4,
"func_score_A": 0,
"func_score_B":0.7
},
{"func_id": 5,
"func_score_A": 0,
"func_score_B":0.8
}
]


Note:










share|improve this question


























    up vote
    0
    down vote

    favorite
    1












    I am using Node.js for programming,
    In the below array of Objects A and B have the arrays with have some duplicates values also, but we have to skip the duplicated for only based on func_id of the arrays. In the array C we have push both A and B func_score values based on func_id and func_score_A from A(func_score) array and func_score_B from B(func_score) array.



    Sample Code:



    var A = [{
    "func_id": 1,
    "func_score": 0.4
    }, {
    "func_id": 2,
    "func_score": 0.5
    }, {
    "func_id": 3,
    "func_score": 0.7
    }];
    var B = [{
    "func_id": 3,
    "func_score": 0.9
    }, {
    "func_id": 4,
    "func_score": 0.7
    }, {
    "func_id": 5,
    "func_score": 0.8
    }];
    var C = ;
    var tmpArray = ;
    A.forEach(function(element) {
    B.forEach(function(loop) {
    if (element.func_id === loop.func_id) {
    var tmpObje = {
    func_id: element.func_id,
    func_sore_A: element.func_score,
    func_sore_B: loop.func_score
    }
    tmpArray.push(tmpObje);
    C.push(tmpObje);
    return;
    }
    });
    });

    A.forEach(function(element) {
    tmpArray.forEach(function(loop) {
    if (element.func_id !== loop.func_id) {
    var smsObj = {
    func_id: element.func_id,
    func_sore_A: element.func_score,
    func_sore_B: 0
    }
    C.push(smsObj);
    return;
    }
    });
    });

    B.forEach(function(element) {
    tmpArray.forEach(function(loop) {
    if (element.func_id !== loop.func_id) {
    var domineObj = {
    func_id: element.func_id,
    func_sore_A: 0,
    func_sore_B: loop.func_score
    }
    C.push(domineObj);
    return;
    }
    });
    });
    console.log(C);


    Expected Output



    [
    {"func_id": 1,
    "func_score_A": 0.4,
    "func_score_B":0
    },
    {"func_id": 2,
    "func_score_A": 0.5,
    "func_score_B":0
    },
    {"func_id": 3,
    "func_score_A": 0.7,
    "func_score_B":0.9
    },
    {"func_id": 4,
    "func_score_A": 0,
    "func_score_B":0.7
    },
    {"func_id": 5,
    "func_score_A": 0,
    "func_score_B":0.8
    }
    ]


    Note:










    share|improve this question
























      up vote
      0
      down vote

      favorite
      1









      up vote
      0
      down vote

      favorite
      1






      1





      I am using Node.js for programming,
      In the below array of Objects A and B have the arrays with have some duplicates values also, but we have to skip the duplicated for only based on func_id of the arrays. In the array C we have push both A and B func_score values based on func_id and func_score_A from A(func_score) array and func_score_B from B(func_score) array.



      Sample Code:



      var A = [{
      "func_id": 1,
      "func_score": 0.4
      }, {
      "func_id": 2,
      "func_score": 0.5
      }, {
      "func_id": 3,
      "func_score": 0.7
      }];
      var B = [{
      "func_id": 3,
      "func_score": 0.9
      }, {
      "func_id": 4,
      "func_score": 0.7
      }, {
      "func_id": 5,
      "func_score": 0.8
      }];
      var C = ;
      var tmpArray = ;
      A.forEach(function(element) {
      B.forEach(function(loop) {
      if (element.func_id === loop.func_id) {
      var tmpObje = {
      func_id: element.func_id,
      func_sore_A: element.func_score,
      func_sore_B: loop.func_score
      }
      tmpArray.push(tmpObje);
      C.push(tmpObje);
      return;
      }
      });
      });

      A.forEach(function(element) {
      tmpArray.forEach(function(loop) {
      if (element.func_id !== loop.func_id) {
      var smsObj = {
      func_id: element.func_id,
      func_sore_A: element.func_score,
      func_sore_B: 0
      }
      C.push(smsObj);
      return;
      }
      });
      });

      B.forEach(function(element) {
      tmpArray.forEach(function(loop) {
      if (element.func_id !== loop.func_id) {
      var domineObj = {
      func_id: element.func_id,
      func_sore_A: 0,
      func_sore_B: loop.func_score
      }
      C.push(domineObj);
      return;
      }
      });
      });
      console.log(C);


      Expected Output



      [
      {"func_id": 1,
      "func_score_A": 0.4,
      "func_score_B":0
      },
      {"func_id": 2,
      "func_score_A": 0.5,
      "func_score_B":0
      },
      {"func_id": 3,
      "func_score_A": 0.7,
      "func_score_B":0.9
      },
      {"func_id": 4,
      "func_score_A": 0,
      "func_score_B":0.7
      },
      {"func_id": 5,
      "func_score_A": 0,
      "func_score_B":0.8
      }
      ]


      Note:










      share|improve this question













      I am using Node.js for programming,
      In the below array of Objects A and B have the arrays with have some duplicates values also, but we have to skip the duplicated for only based on func_id of the arrays. In the array C we have push both A and B func_score values based on func_id and func_score_A from A(func_score) array and func_score_B from B(func_score) array.



      Sample Code:



      var A = [{
      "func_id": 1,
      "func_score": 0.4
      }, {
      "func_id": 2,
      "func_score": 0.5
      }, {
      "func_id": 3,
      "func_score": 0.7
      }];
      var B = [{
      "func_id": 3,
      "func_score": 0.9
      }, {
      "func_id": 4,
      "func_score": 0.7
      }, {
      "func_id": 5,
      "func_score": 0.8
      }];
      var C = ;
      var tmpArray = ;
      A.forEach(function(element) {
      B.forEach(function(loop) {
      if (element.func_id === loop.func_id) {
      var tmpObje = {
      func_id: element.func_id,
      func_sore_A: element.func_score,
      func_sore_B: loop.func_score
      }
      tmpArray.push(tmpObje);
      C.push(tmpObje);
      return;
      }
      });
      });

      A.forEach(function(element) {
      tmpArray.forEach(function(loop) {
      if (element.func_id !== loop.func_id) {
      var smsObj = {
      func_id: element.func_id,
      func_sore_A: element.func_score,
      func_sore_B: 0
      }
      C.push(smsObj);
      return;
      }
      });
      });

      B.forEach(function(element) {
      tmpArray.forEach(function(loop) {
      if (element.func_id !== loop.func_id) {
      var domineObj = {
      func_id: element.func_id,
      func_sore_A: 0,
      func_sore_B: loop.func_score
      }
      C.push(domineObj);
      return;
      }
      });
      });
      console.log(C);


      Expected Output



      [
      {"func_id": 1,
      "func_score_A": 0.4,
      "func_score_B":0
      },
      {"func_id": 2,
      "func_score_A": 0.5,
      "func_score_B":0
      },
      {"func_id": 3,
      "func_score_A": 0.7,
      "func_score_B":0.9
      },
      {"func_id": 4,
      "func_score_A": 0,
      "func_score_B":0.7
      },
      {"func_id": 5,
      "func_score_A": 0,
      "func_score_B":0.8
      }
      ]


      Note:







      arrays node.js object arraylist arrayobject






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 at 15:06









      siva

      302415




      302415
























          3 Answers
          3






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          Here's an approach that might be a little simpler.






          var A = [{
          "func_id": 1,
          "func_score": 0.4
          }, {
          "func_id": 2,
          "func_score": 0.5
          }, {
          "func_id": 3,
          "func_score": 0.7
          }];

          var B = [{
          "func_id": 3,
          "func_score": 0.9
          }, {
          "func_id": 4,
          "func_score": 0.7
          }, {
          "func_id": 5,
          "func_score": 0.8
          }];

          let C = A.map(e => {
          return {
          func_id: e.func_id,
          func_score_A: e.func_score,
          func_score_B: 0
          };
          });
          B.forEach(e => {
          let i = C.findIndex(x => x.func_id == e.func_id);
          if (i >= 0) {
          C[i].func_score_B = e.func_score;
          } else {
          C.push({
          func_id: e.func_id,
          func_score_A: 0,
          func_score_B: e.func_score
          })
          }
          });
          console.log(C);








          share|improve this answer























          • Hi Jim B , Your approach working fine like exactly what i want. Thank you so much.
            – siva
            Nov 22 at 9:14


















          up vote
          0
          down vote













          Your bug is quite simple, first replace all sore with score. Then in your B.forEach() loop, you possibly made the mistake of taking loop.func_score instead of element.func_score.



          B.forEach(function(element) {
          tmpArray.forEach(function(loop) {
          if (element.func_id !== loop.func_id) {
          var domineObj = {
          func_id: element.func_id,
          func_sore_A: 0,
          // loop should be element
          // func_sore_B: loop.func_score
          func_sore_B: element.func_score
          }
          C.push(domineObj);
          return;
          }
          });
          });





          share|improve this answer























          • Hi ssemilla, even i changed the code as per you suggestion but still i didn't get Expected Output but,below another guy Mr Jim given another little simpler approach , its working fine. Any way thank you for your stuff.
            – siva
            Nov 22 at 9:13










          • Sure, I also suggest just simplifying your code.
            – ssemilla
            Nov 22 at 9:15


















          up vote
          -1
          down vote













          You can do this without all the code below just do var C = A.concat(B)



          var A = [{
          "func_id": 1,
          "func_score": 0.4
          }, {
          "func_id": 2,
          "func_score": 0.5
          }, {
          "func_id": 3,
          "func_score": 0.7
          }];
          var B = [{
          "func_id": 3,
          "func_score": 0.9
          }, {
          "func_id": 4,
          "func_score": 0.7
          }, {
          "func_id": 5,
          "func_score": 0.8
          }];

          //check the console for output
          console.log(A.concat(B));


          working example: https://jsfiddle.net/1e304w7t/






          share|improve this answer





















          • Hi Rick ,A.concat(B) is not correct solution, Kindly see the Expected Output
            – siva
            Nov 21 at 16:32











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53414948%2fhow-to-merge-array-of-objects-a-and-b-and-form-array-of-object-c-contains-new-ke%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          3 Answers
          3






          active

          oldest

          votes








          3 Answers
          3






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          Here's an approach that might be a little simpler.






          var A = [{
          "func_id": 1,
          "func_score": 0.4
          }, {
          "func_id": 2,
          "func_score": 0.5
          }, {
          "func_id": 3,
          "func_score": 0.7
          }];

          var B = [{
          "func_id": 3,
          "func_score": 0.9
          }, {
          "func_id": 4,
          "func_score": 0.7
          }, {
          "func_id": 5,
          "func_score": 0.8
          }];

          let C = A.map(e => {
          return {
          func_id: e.func_id,
          func_score_A: e.func_score,
          func_score_B: 0
          };
          });
          B.forEach(e => {
          let i = C.findIndex(x => x.func_id == e.func_id);
          if (i >= 0) {
          C[i].func_score_B = e.func_score;
          } else {
          C.push({
          func_id: e.func_id,
          func_score_A: 0,
          func_score_B: e.func_score
          })
          }
          });
          console.log(C);








          share|improve this answer























          • Hi Jim B , Your approach working fine like exactly what i want. Thank you so much.
            – siva
            Nov 22 at 9:14















          up vote
          1
          down vote



          accepted










          Here's an approach that might be a little simpler.






          var A = [{
          "func_id": 1,
          "func_score": 0.4
          }, {
          "func_id": 2,
          "func_score": 0.5
          }, {
          "func_id": 3,
          "func_score": 0.7
          }];

          var B = [{
          "func_id": 3,
          "func_score": 0.9
          }, {
          "func_id": 4,
          "func_score": 0.7
          }, {
          "func_id": 5,
          "func_score": 0.8
          }];

          let C = A.map(e => {
          return {
          func_id: e.func_id,
          func_score_A: e.func_score,
          func_score_B: 0
          };
          });
          B.forEach(e => {
          let i = C.findIndex(x => x.func_id == e.func_id);
          if (i >= 0) {
          C[i].func_score_B = e.func_score;
          } else {
          C.push({
          func_id: e.func_id,
          func_score_A: 0,
          func_score_B: e.func_score
          })
          }
          });
          console.log(C);








          share|improve this answer























          • Hi Jim B , Your approach working fine like exactly what i want. Thank you so much.
            – siva
            Nov 22 at 9:14













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          Here's an approach that might be a little simpler.






          var A = [{
          "func_id": 1,
          "func_score": 0.4
          }, {
          "func_id": 2,
          "func_score": 0.5
          }, {
          "func_id": 3,
          "func_score": 0.7
          }];

          var B = [{
          "func_id": 3,
          "func_score": 0.9
          }, {
          "func_id": 4,
          "func_score": 0.7
          }, {
          "func_id": 5,
          "func_score": 0.8
          }];

          let C = A.map(e => {
          return {
          func_id: e.func_id,
          func_score_A: e.func_score,
          func_score_B: 0
          };
          });
          B.forEach(e => {
          let i = C.findIndex(x => x.func_id == e.func_id);
          if (i >= 0) {
          C[i].func_score_B = e.func_score;
          } else {
          C.push({
          func_id: e.func_id,
          func_score_A: 0,
          func_score_B: e.func_score
          })
          }
          });
          console.log(C);








          share|improve this answer














          Here's an approach that might be a little simpler.






          var A = [{
          "func_id": 1,
          "func_score": 0.4
          }, {
          "func_id": 2,
          "func_score": 0.5
          }, {
          "func_id": 3,
          "func_score": 0.7
          }];

          var B = [{
          "func_id": 3,
          "func_score": 0.9
          }, {
          "func_id": 4,
          "func_score": 0.7
          }, {
          "func_id": 5,
          "func_score": 0.8
          }];

          let C = A.map(e => {
          return {
          func_id: e.func_id,
          func_score_A: e.func_score,
          func_score_B: 0
          };
          });
          B.forEach(e => {
          let i = C.findIndex(x => x.func_id == e.func_id);
          if (i >= 0) {
          C[i].func_score_B = e.func_score;
          } else {
          C.push({
          func_id: e.func_id,
          func_score_A: 0,
          func_score_B: e.func_score
          })
          }
          });
          console.log(C);








          var A = [{
          "func_id": 1,
          "func_score": 0.4
          }, {
          "func_id": 2,
          "func_score": 0.5
          }, {
          "func_id": 3,
          "func_score": 0.7
          }];

          var B = [{
          "func_id": 3,
          "func_score": 0.9
          }, {
          "func_id": 4,
          "func_score": 0.7
          }, {
          "func_id": 5,
          "func_score": 0.8
          }];

          let C = A.map(e => {
          return {
          func_id: e.func_id,
          func_score_A: e.func_score,
          func_score_B: 0
          };
          });
          B.forEach(e => {
          let i = C.findIndex(x => x.func_id == e.func_id);
          if (i >= 0) {
          C[i].func_score_B = e.func_score;
          } else {
          C.push({
          func_id: e.func_id,
          func_score_A: 0,
          func_score_B: e.func_score
          })
          }
          });
          console.log(C);





          var A = [{
          "func_id": 1,
          "func_score": 0.4
          }, {
          "func_id": 2,
          "func_score": 0.5
          }, {
          "func_id": 3,
          "func_score": 0.7
          }];

          var B = [{
          "func_id": 3,
          "func_score": 0.9
          }, {
          "func_id": 4,
          "func_score": 0.7
          }, {
          "func_id": 5,
          "func_score": 0.8
          }];

          let C = A.map(e => {
          return {
          func_id: e.func_id,
          func_score_A: e.func_score,
          func_score_B: 0
          };
          });
          B.forEach(e => {
          let i = C.findIndex(x => x.func_id == e.func_id);
          if (i >= 0) {
          C[i].func_score_B = e.func_score;
          } else {
          C.push({
          func_id: e.func_id,
          func_score_A: 0,
          func_score_B: e.func_score
          })
          }
          });
          console.log(C);






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 21 at 21:18

























          answered Nov 21 at 20:57









          Jim B.

          2,6261928




          2,6261928












          • Hi Jim B , Your approach working fine like exactly what i want. Thank you so much.
            – siva
            Nov 22 at 9:14


















          • Hi Jim B , Your approach working fine like exactly what i want. Thank you so much.
            – siva
            Nov 22 at 9:14
















          Hi Jim B , Your approach working fine like exactly what i want. Thank you so much.
          – siva
          Nov 22 at 9:14




          Hi Jim B , Your approach working fine like exactly what i want. Thank you so much.
          – siva
          Nov 22 at 9:14












          up vote
          0
          down vote













          Your bug is quite simple, first replace all sore with score. Then in your B.forEach() loop, you possibly made the mistake of taking loop.func_score instead of element.func_score.



          B.forEach(function(element) {
          tmpArray.forEach(function(loop) {
          if (element.func_id !== loop.func_id) {
          var domineObj = {
          func_id: element.func_id,
          func_sore_A: 0,
          // loop should be element
          // func_sore_B: loop.func_score
          func_sore_B: element.func_score
          }
          C.push(domineObj);
          return;
          }
          });
          });





          share|improve this answer























          • Hi ssemilla, even i changed the code as per you suggestion but still i didn't get Expected Output but,below another guy Mr Jim given another little simpler approach , its working fine. Any way thank you for your stuff.
            – siva
            Nov 22 at 9:13










          • Sure, I also suggest just simplifying your code.
            – ssemilla
            Nov 22 at 9:15















          up vote
          0
          down vote













          Your bug is quite simple, first replace all sore with score. Then in your B.forEach() loop, you possibly made the mistake of taking loop.func_score instead of element.func_score.



          B.forEach(function(element) {
          tmpArray.forEach(function(loop) {
          if (element.func_id !== loop.func_id) {
          var domineObj = {
          func_id: element.func_id,
          func_sore_A: 0,
          // loop should be element
          // func_sore_B: loop.func_score
          func_sore_B: element.func_score
          }
          C.push(domineObj);
          return;
          }
          });
          });





          share|improve this answer























          • Hi ssemilla, even i changed the code as per you suggestion but still i didn't get Expected Output but,below another guy Mr Jim given another little simpler approach , its working fine. Any way thank you for your stuff.
            – siva
            Nov 22 at 9:13










          • Sure, I also suggest just simplifying your code.
            – ssemilla
            Nov 22 at 9:15













          up vote
          0
          down vote










          up vote
          0
          down vote









          Your bug is quite simple, first replace all sore with score. Then in your B.forEach() loop, you possibly made the mistake of taking loop.func_score instead of element.func_score.



          B.forEach(function(element) {
          tmpArray.forEach(function(loop) {
          if (element.func_id !== loop.func_id) {
          var domineObj = {
          func_id: element.func_id,
          func_sore_A: 0,
          // loop should be element
          // func_sore_B: loop.func_score
          func_sore_B: element.func_score
          }
          C.push(domineObj);
          return;
          }
          });
          });





          share|improve this answer














          Your bug is quite simple, first replace all sore with score. Then in your B.forEach() loop, you possibly made the mistake of taking loop.func_score instead of element.func_score.



          B.forEach(function(element) {
          tmpArray.forEach(function(loop) {
          if (element.func_id !== loop.func_id) {
          var domineObj = {
          func_id: element.func_id,
          func_sore_A: 0,
          // loop should be element
          // func_sore_B: loop.func_score
          func_sore_B: element.func_score
          }
          C.push(domineObj);
          return;
          }
          });
          });






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 22 at 5:47

























          answered Nov 22 at 3:47









          ssemilla

          2,687423




          2,687423












          • Hi ssemilla, even i changed the code as per you suggestion but still i didn't get Expected Output but,below another guy Mr Jim given another little simpler approach , its working fine. Any way thank you for your stuff.
            – siva
            Nov 22 at 9:13










          • Sure, I also suggest just simplifying your code.
            – ssemilla
            Nov 22 at 9:15


















          • Hi ssemilla, even i changed the code as per you suggestion but still i didn't get Expected Output but,below another guy Mr Jim given another little simpler approach , its working fine. Any way thank you for your stuff.
            – siva
            Nov 22 at 9:13










          • Sure, I also suggest just simplifying your code.
            – ssemilla
            Nov 22 at 9:15
















          Hi ssemilla, even i changed the code as per you suggestion but still i didn't get Expected Output but,below another guy Mr Jim given another little simpler approach , its working fine. Any way thank you for your stuff.
          – siva
          Nov 22 at 9:13




          Hi ssemilla, even i changed the code as per you suggestion but still i didn't get Expected Output but,below another guy Mr Jim given another little simpler approach , its working fine. Any way thank you for your stuff.
          – siva
          Nov 22 at 9:13












          Sure, I also suggest just simplifying your code.
          – ssemilla
          Nov 22 at 9:15




          Sure, I also suggest just simplifying your code.
          – ssemilla
          Nov 22 at 9:15










          up vote
          -1
          down vote













          You can do this without all the code below just do var C = A.concat(B)



          var A = [{
          "func_id": 1,
          "func_score": 0.4
          }, {
          "func_id": 2,
          "func_score": 0.5
          }, {
          "func_id": 3,
          "func_score": 0.7
          }];
          var B = [{
          "func_id": 3,
          "func_score": 0.9
          }, {
          "func_id": 4,
          "func_score": 0.7
          }, {
          "func_id": 5,
          "func_score": 0.8
          }];

          //check the console for output
          console.log(A.concat(B));


          working example: https://jsfiddle.net/1e304w7t/






          share|improve this answer





















          • Hi Rick ,A.concat(B) is not correct solution, Kindly see the Expected Output
            – siva
            Nov 21 at 16:32















          up vote
          -1
          down vote













          You can do this without all the code below just do var C = A.concat(B)



          var A = [{
          "func_id": 1,
          "func_score": 0.4
          }, {
          "func_id": 2,
          "func_score": 0.5
          }, {
          "func_id": 3,
          "func_score": 0.7
          }];
          var B = [{
          "func_id": 3,
          "func_score": 0.9
          }, {
          "func_id": 4,
          "func_score": 0.7
          }, {
          "func_id": 5,
          "func_score": 0.8
          }];

          //check the console for output
          console.log(A.concat(B));


          working example: https://jsfiddle.net/1e304w7t/






          share|improve this answer





















          • Hi Rick ,A.concat(B) is not correct solution, Kindly see the Expected Output
            – siva
            Nov 21 at 16:32













          up vote
          -1
          down vote










          up vote
          -1
          down vote









          You can do this without all the code below just do var C = A.concat(B)



          var A = [{
          "func_id": 1,
          "func_score": 0.4
          }, {
          "func_id": 2,
          "func_score": 0.5
          }, {
          "func_id": 3,
          "func_score": 0.7
          }];
          var B = [{
          "func_id": 3,
          "func_score": 0.9
          }, {
          "func_id": 4,
          "func_score": 0.7
          }, {
          "func_id": 5,
          "func_score": 0.8
          }];

          //check the console for output
          console.log(A.concat(B));


          working example: https://jsfiddle.net/1e304w7t/






          share|improve this answer












          You can do this without all the code below just do var C = A.concat(B)



          var A = [{
          "func_id": 1,
          "func_score": 0.4
          }, {
          "func_id": 2,
          "func_score": 0.5
          }, {
          "func_id": 3,
          "func_score": 0.7
          }];
          var B = [{
          "func_id": 3,
          "func_score": 0.9
          }, {
          "func_id": 4,
          "func_score": 0.7
          }, {
          "func_id": 5,
          "func_score": 0.8
          }];

          //check the console for output
          console.log(A.concat(B));


          working example: https://jsfiddle.net/1e304w7t/







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 at 15:14









          Rick Grendel

          50119




          50119












          • Hi Rick ,A.concat(B) is not correct solution, Kindly see the Expected Output
            – siva
            Nov 21 at 16:32


















          • Hi Rick ,A.concat(B) is not correct solution, Kindly see the Expected Output
            – siva
            Nov 21 at 16:32
















          Hi Rick ,A.concat(B) is not correct solution, Kindly see the Expected Output
          – siva
          Nov 21 at 16:32




          Hi Rick ,A.concat(B) is not correct solution, Kindly see the Expected Output
          – siva
          Nov 21 at 16:32


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53414948%2fhow-to-merge-array-of-objects-a-and-b-and-form-array-of-object-c-contains-new-ke%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Berounka

          Sphinx de Gizeh

          Different font size/position of beamer's navigation symbols template's content depending on regular/plain...