How to merge three different arrays by comparing with id? in Angular 6 The 2019 Stack Overflow Developer Survey Results Are InWhat is destructuring assignment and its uses?How can I merge properties of two JavaScript objects dynamically?How do I check if an array includes an object in JavaScript?How to append something to an array?How to insert an item into an array at a specific index (JavaScript)?How do I empty an array in JavaScript?How to merge two arrays in JavaScript and de-duplicate itemsHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?How to compare arrays in JavaScript?Merge/flatten an array of arrays

How to charge AirPods to keep battery healthy?

What information about me do stores get via my credit card?

Is it ethical to upload a automatically generated paper to a non peer-reviewed site as part of a larger research?

What's the name of these plastic connectors

Inverse Relationship Between Precision and Recall

Slides for 30 min~1 hr Skype tenure track application interview

Does HR tell a hiring manager about salary negotiations?

Ubuntu Server install with full GUI

How to translate "being like"?

Falsification in Math vs Science

What could be the right powersource for 15 seconds lifespan disposable giant chainsaw?

Match Roman Numerals

Can withdrawing asylum be illegal?

The phrase "to the numbers born"?

Can we generate random numbers using irrational numbers like π and e?

If I can cast sorceries at instant speed, can I use sorcery-speed activated abilities at instant speed?

Is bread bad for ducks?

A word that means fill it to the required quantity

Kerning for subscripts of sigma?

Button changing its text & action. Good or terrible?

APIPA and LAN Broadcast Domain

Why doesn't UInt have a toDouble()?

What is the motivation for a law requiring 2 parties to consent for recording a conversation

Can there be female White Walkers?



How to merge three different arrays by comparing with id? in Angular 6



The 2019 Stack Overflow Developer Survey Results Are InWhat is destructuring assignment and its uses?How can I merge properties of two JavaScript objects dynamically?How do I check if an array includes an object in JavaScript?How to append something to an array?How to insert an item into an array at a specific index (JavaScript)?How do I empty an array in JavaScript?How to merge two arrays in JavaScript and de-duplicate itemsHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?How to compare arrays in JavaScript?Merge/flatten an array of arrays



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








3















Arrays:



 array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];


Required result is:



resultarray = [
id:1, name: "raju", degree:"b.com",age:20,
id:2, name: "ravi",
id:3, degree:"b.a", age:21,
id:4, name:"john", degree:"c.a",
id:5, degree:"horticulture",
id:6, name:"jack", age:27,
id:7, age:25
]


i have tried different functions and tried for two arrays but not able to merge the object which doesnt have id to compare..










share|improve this question






























    3















    Arrays:



     array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
    array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
    array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];


    Required result is:



    resultarray = [
    id:1, name: "raju", degree:"b.com",age:20,
    id:2, name: "ravi",
    id:3, degree:"b.a", age:21,
    id:4, name:"john", degree:"c.a",
    id:5, degree:"horticulture",
    id:6, name:"jack", age:27,
    id:7, age:25
    ]


    i have tried different functions and tried for two arrays but not able to merge the object which doesnt have id to compare..










    share|improve this question


























      3












      3








      3


      2






      Arrays:



       array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
      array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
      array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];


      Required result is:



      resultarray = [
      id:1, name: "raju", degree:"b.com",age:20,
      id:2, name: "ravi",
      id:3, degree:"b.a", age:21,
      id:4, name:"john", degree:"c.a",
      id:5, degree:"horticulture",
      id:6, name:"jack", age:27,
      id:7, age:25
      ]


      i have tried different functions and tried for two arrays but not able to merge the object which doesnt have id to compare..










      share|improve this question
















      Arrays:



       array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
      array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
      array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];


      Required result is:



      resultarray = [
      id:1, name: "raju", degree:"b.com",age:20,
      id:2, name: "ravi",
      id:3, degree:"b.a", age:21,
      id:4, name:"john", degree:"c.a",
      id:5, degree:"horticulture",
      id:6, name:"jack", age:27,
      id:7, age:25
      ]


      i have tried different functions and tried for two arrays but not able to merge the object which doesnt have id to compare..







      javascript typescript angular6






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 22 at 4:50









      pavan skipo

      531115




      531115










      asked Mar 22 at 4:42









      Phani Kumar DevuPhani Kumar Devu

      185




      185






















          3 Answers
          3






          active

          oldest

          votes


















          7














          You can use reduce and destructuring



          Here idea is



          • First merge all the arrays in one array.

          • Now using reduce we create id as key in op object

          • If id key is already there we merge the inp and op[inp.id]

          • If id is not there we create a new key with value inp




          let array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
          let array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
          let array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];

          let temp = [...array1,...array2,...array3]

          let op = temp.reduce((op,inp)=>,)

          console.log(Object.values(op))








          share|improve this answer

























          • can we keep this result array as a child to one parent id(another different id )

            – Phani Kumar Devu
            Mar 22 at 5:17






          • 1





            @PhaniKumarDevu i am unable to understand what you meant by above line, can you add explanation or some example ?

            – Code Maniac
            Mar 22 at 5:25











          • i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

            – Phani Kumar Devu
            Mar 22 at 5:28






          • 1





            You can simply set userrating key's value to output we are getting, userId: 201, userrating: Object.values(op) something like this

            – Code Maniac
            Mar 22 at 5:29



















          2














          a possible solution:






          let array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
          let array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
          let array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];

          let resp = [].concat(array1, array2, array3).reduce((acc, ele) =>
          let obj = acc.find(x => x.id === ele.id);
          return obj ? (Object.keys(ele).forEach(x => obj[x] = ele[x]), acc) : acc.concat(ele);
          , [])

          console.log(resp)








          share|improve this answer























          • Thanks for your answer... this one also worked...

            – Phani Kumar Devu
            Mar 22 at 5:09











          • can we keep this result array as a child to one parent id(another different id )

            – Phani Kumar Devu
            Mar 22 at 5:18






          • 1





            yeah, could you elaborate how do you pretend decide which one is parent?

            – guijob
            Mar 22 at 5:21











          • i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

            – Phani Kumar Devu
            Mar 22 at 5:26


















          1














          There will be better solutions than this, but this is what I've tried:



          Merging the 3 arrays into one :



          let array = [...array1, ...array2, ...array3]


          Looping through the items and then putting the values to "object"



          let object = 
          array.forEach((item) =>
          object[item.id] = ...object[item.id],...item)


          Final solution



          result = Object.values(object)


          object variable will contain



          object = '1': id: 1, age: 20, name: 'raju', degree: 'b.com' ,
          '2': id: 2, name: 'ravi' ,
          '3': id: 3, age: 21, degree: 'b.a' ,
          '4': id: 4, degree: 'c.a', name: 'john' ,
          '5': id: 5, degree: 'horticulture' ,
          '6': id: 6, age: 27, name: 'jack' ,
          '7': id: 7, age: 25


          result variable will contain



          result = [ id: 1, age: 20, name: 'raju', degree: 'b.com' ,
          id: 2, name: 'ravi' ,
          id: 3, age: 21, degree: 'b.a' ,
          id: 4, degree: 'c.a', name: 'john' ,
          id: 5, degree: 'horticulture' ,
          id: 6, age: 27, name: 'jack' ,
          id: 7, age: 25 ]





          share|improve this answer




















          • 1





            Oh by the i was adding this solution, 2 people have already solved and posted their answers :)

            – pavan skipo
            Mar 22 at 5:14











          • can we keep this result array as a child to one parent id(another different id )

            – Phani Kumar Devu
            Mar 22 at 5:17






          • 1





            yeah we can it is a list of objects. wait ill update the answer

            – pavan skipo
            Mar 22 at 5:21











          • i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

            – Phani Kumar Devu
            Mar 22 at 5:27











          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',
          autoActivateHeartbeat: false,
          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%2f55293036%2fhow-to-merge-three-different-arrays-by-comparing-with-id-in-angular-6%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









          7














          You can use reduce and destructuring



          Here idea is



          • First merge all the arrays in one array.

          • Now using reduce we create id as key in op object

          • If id key is already there we merge the inp and op[inp.id]

          • If id is not there we create a new key with value inp




          let array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
          let array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
          let array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];

          let temp = [...array1,...array2,...array3]

          let op = temp.reduce((op,inp)=>,)

          console.log(Object.values(op))








          share|improve this answer

























          • can we keep this result array as a child to one parent id(another different id )

            – Phani Kumar Devu
            Mar 22 at 5:17






          • 1





            @PhaniKumarDevu i am unable to understand what you meant by above line, can you add explanation or some example ?

            – Code Maniac
            Mar 22 at 5:25











          • i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

            – Phani Kumar Devu
            Mar 22 at 5:28






          • 1





            You can simply set userrating key's value to output we are getting, userId: 201, userrating: Object.values(op) something like this

            – Code Maniac
            Mar 22 at 5:29
















          7














          You can use reduce and destructuring



          Here idea is



          • First merge all the arrays in one array.

          • Now using reduce we create id as key in op object

          • If id key is already there we merge the inp and op[inp.id]

          • If id is not there we create a new key with value inp




          let array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
          let array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
          let array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];

          let temp = [...array1,...array2,...array3]

          let op = temp.reduce((op,inp)=>,)

          console.log(Object.values(op))








          share|improve this answer

























          • can we keep this result array as a child to one parent id(another different id )

            – Phani Kumar Devu
            Mar 22 at 5:17






          • 1





            @PhaniKumarDevu i am unable to understand what you meant by above line, can you add explanation or some example ?

            – Code Maniac
            Mar 22 at 5:25











          • i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

            – Phani Kumar Devu
            Mar 22 at 5:28






          • 1





            You can simply set userrating key's value to output we are getting, userId: 201, userrating: Object.values(op) something like this

            – Code Maniac
            Mar 22 at 5:29














          7












          7








          7







          You can use reduce and destructuring



          Here idea is



          • First merge all the arrays in one array.

          • Now using reduce we create id as key in op object

          • If id key is already there we merge the inp and op[inp.id]

          • If id is not there we create a new key with value inp




          let array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
          let array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
          let array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];

          let temp = [...array1,...array2,...array3]

          let op = temp.reduce((op,inp)=>,)

          console.log(Object.values(op))








          share|improve this answer















          You can use reduce and destructuring



          Here idea is



          • First merge all the arrays in one array.

          • Now using reduce we create id as key in op object

          • If id key is already there we merge the inp and op[inp.id]

          • If id is not there we create a new key with value inp




          let array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
          let array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
          let array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];

          let temp = [...array1,...array2,...array3]

          let op = temp.reduce((op,inp)=>,)

          console.log(Object.values(op))








          let array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
          let array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
          let array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];

          let temp = [...array1,...array2,...array3]

          let op = temp.reduce((op,inp)=>,)

          console.log(Object.values(op))





          let array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
          let array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
          let array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];

          let temp = [...array1,...array2,...array3]

          let op = temp.reduce((op,inp)=>,)

          console.log(Object.values(op))






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 22 at 5:02

























          answered Mar 22 at 4:56









          Code ManiacCode Maniac

          11.9k2934




          11.9k2934












          • can we keep this result array as a child to one parent id(another different id )

            – Phani Kumar Devu
            Mar 22 at 5:17






          • 1





            @PhaniKumarDevu i am unable to understand what you meant by above line, can you add explanation or some example ?

            – Code Maniac
            Mar 22 at 5:25











          • i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

            – Phani Kumar Devu
            Mar 22 at 5:28






          • 1





            You can simply set userrating key's value to output we are getting, userId: 201, userrating: Object.values(op) something like this

            – Code Maniac
            Mar 22 at 5:29


















          • can we keep this result array as a child to one parent id(another different id )

            – Phani Kumar Devu
            Mar 22 at 5:17






          • 1





            @PhaniKumarDevu i am unable to understand what you meant by above line, can you add explanation or some example ?

            – Code Maniac
            Mar 22 at 5:25











          • i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

            – Phani Kumar Devu
            Mar 22 at 5:28






          • 1





            You can simply set userrating key's value to output we are getting, userId: 201, userrating: Object.values(op) something like this

            – Code Maniac
            Mar 22 at 5:29

















          can we keep this result array as a child to one parent id(another different id )

          – Phani Kumar Devu
          Mar 22 at 5:17





          can we keep this result array as a child to one parent id(another different id )

          – Phani Kumar Devu
          Mar 22 at 5:17




          1




          1





          @PhaniKumarDevu i am unable to understand what you meant by above line, can you add explanation or some example ?

          – Code Maniac
          Mar 22 at 5:25





          @PhaniKumarDevu i am unable to understand what you meant by above line, can you add explanation or some example ?

          – Code Maniac
          Mar 22 at 5:25













          i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

          – Phani Kumar Devu
          Mar 22 at 5:28





          i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

          – Phani Kumar Devu
          Mar 22 at 5:28




          1




          1





          You can simply set userrating key's value to output we are getting, userId: 201, userrating: Object.values(op) something like this

          – Code Maniac
          Mar 22 at 5:29






          You can simply set userrating key's value to output we are getting, userId: 201, userrating: Object.values(op) something like this

          – Code Maniac
          Mar 22 at 5:29














          2














          a possible solution:






          let array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
          let array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
          let array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];

          let resp = [].concat(array1, array2, array3).reduce((acc, ele) =>
          let obj = acc.find(x => x.id === ele.id);
          return obj ? (Object.keys(ele).forEach(x => obj[x] = ele[x]), acc) : acc.concat(ele);
          , [])

          console.log(resp)








          share|improve this answer























          • Thanks for your answer... this one also worked...

            – Phani Kumar Devu
            Mar 22 at 5:09











          • can we keep this result array as a child to one parent id(another different id )

            – Phani Kumar Devu
            Mar 22 at 5:18






          • 1





            yeah, could you elaborate how do you pretend decide which one is parent?

            – guijob
            Mar 22 at 5:21











          • i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

            – Phani Kumar Devu
            Mar 22 at 5:26















          2














          a possible solution:






          let array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
          let array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
          let array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];

          let resp = [].concat(array1, array2, array3).reduce((acc, ele) =>
          let obj = acc.find(x => x.id === ele.id);
          return obj ? (Object.keys(ele).forEach(x => obj[x] = ele[x]), acc) : acc.concat(ele);
          , [])

          console.log(resp)








          share|improve this answer























          • Thanks for your answer... this one also worked...

            – Phani Kumar Devu
            Mar 22 at 5:09











          • can we keep this result array as a child to one parent id(another different id )

            – Phani Kumar Devu
            Mar 22 at 5:18






          • 1





            yeah, could you elaborate how do you pretend decide which one is parent?

            – guijob
            Mar 22 at 5:21











          • i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

            – Phani Kumar Devu
            Mar 22 at 5:26













          2












          2








          2







          a possible solution:






          let array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
          let array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
          let array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];

          let resp = [].concat(array1, array2, array3).reduce((acc, ele) =>
          let obj = acc.find(x => x.id === ele.id);
          return obj ? (Object.keys(ele).forEach(x => obj[x] = ele[x]), acc) : acc.concat(ele);
          , [])

          console.log(resp)








          share|improve this answer













          a possible solution:






          let array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
          let array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
          let array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];

          let resp = [].concat(array1, array2, array3).reduce((acc, ele) =>
          let obj = acc.find(x => x.id === ele.id);
          return obj ? (Object.keys(ele).forEach(x => obj[x] = ele[x]), acc) : acc.concat(ele);
          , [])

          console.log(resp)








          let array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
          let array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
          let array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];

          let resp = [].concat(array1, array2, array3).reduce((acc, ele) =>
          let obj = acc.find(x => x.id === ele.id);
          return obj ? (Object.keys(ele).forEach(x => obj[x] = ele[x]), acc) : acc.concat(ele);
          , [])

          console.log(resp)





          let array1 = [id:1, name:"raju",id:2, name:"ravi",id:4, name:"john",id:6, name:"jack"];
          let array2= [id:1, degree:"b.com",id:3, degree:"b.a",id:4, degree:"c.a",id:5, degree:"horticulture"];
          let array3= [id:1, age:20,id:3, age:21,id:6, age:27,id:7, age:25];

          let resp = [].concat(array1, array2, array3).reduce((acc, ele) =>
          let obj = acc.find(x => x.id === ele.id);
          return obj ? (Object.keys(ele).forEach(x => obj[x] = ele[x]), acc) : acc.concat(ele);
          , [])

          console.log(resp)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 22 at 4:57









          guijobguijob

          2,23911026




          2,23911026












          • Thanks for your answer... this one also worked...

            – Phani Kumar Devu
            Mar 22 at 5:09











          • can we keep this result array as a child to one parent id(another different id )

            – Phani Kumar Devu
            Mar 22 at 5:18






          • 1





            yeah, could you elaborate how do you pretend decide which one is parent?

            – guijob
            Mar 22 at 5:21











          • i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

            – Phani Kumar Devu
            Mar 22 at 5:26

















          • Thanks for your answer... this one also worked...

            – Phani Kumar Devu
            Mar 22 at 5:09











          • can we keep this result array as a child to one parent id(another different id )

            – Phani Kumar Devu
            Mar 22 at 5:18






          • 1





            yeah, could you elaborate how do you pretend decide which one is parent?

            – guijob
            Mar 22 at 5:21











          • i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

            – Phani Kumar Devu
            Mar 22 at 5:26
















          Thanks for your answer... this one also worked...

          – Phani Kumar Devu
          Mar 22 at 5:09





          Thanks for your answer... this one also worked...

          – Phani Kumar Devu
          Mar 22 at 5:09













          can we keep this result array as a child to one parent id(another different id )

          – Phani Kumar Devu
          Mar 22 at 5:18





          can we keep this result array as a child to one parent id(another different id )

          – Phani Kumar Devu
          Mar 22 at 5:18




          1




          1





          yeah, could you elaborate how do you pretend decide which one is parent?

          – guijob
          Mar 22 at 5:21





          yeah, could you elaborate how do you pretend decide which one is parent?

          – guijob
          Mar 22 at 5:21













          i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

          – Phani Kumar Devu
          Mar 22 at 5:26





          i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

          – Phani Kumar Devu
          Mar 22 at 5:26











          1














          There will be better solutions than this, but this is what I've tried:



          Merging the 3 arrays into one :



          let array = [...array1, ...array2, ...array3]


          Looping through the items and then putting the values to "object"



          let object = 
          array.forEach((item) =>
          object[item.id] = ...object[item.id],...item)


          Final solution



          result = Object.values(object)


          object variable will contain



          object = '1': id: 1, age: 20, name: 'raju', degree: 'b.com' ,
          '2': id: 2, name: 'ravi' ,
          '3': id: 3, age: 21, degree: 'b.a' ,
          '4': id: 4, degree: 'c.a', name: 'john' ,
          '5': id: 5, degree: 'horticulture' ,
          '6': id: 6, age: 27, name: 'jack' ,
          '7': id: 7, age: 25


          result variable will contain



          result = [ id: 1, age: 20, name: 'raju', degree: 'b.com' ,
          id: 2, name: 'ravi' ,
          id: 3, age: 21, degree: 'b.a' ,
          id: 4, degree: 'c.a', name: 'john' ,
          id: 5, degree: 'horticulture' ,
          id: 6, age: 27, name: 'jack' ,
          id: 7, age: 25 ]





          share|improve this answer




















          • 1





            Oh by the i was adding this solution, 2 people have already solved and posted their answers :)

            – pavan skipo
            Mar 22 at 5:14











          • can we keep this result array as a child to one parent id(another different id )

            – Phani Kumar Devu
            Mar 22 at 5:17






          • 1





            yeah we can it is a list of objects. wait ill update the answer

            – pavan skipo
            Mar 22 at 5:21











          • i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

            – Phani Kumar Devu
            Mar 22 at 5:27















          1














          There will be better solutions than this, but this is what I've tried:



          Merging the 3 arrays into one :



          let array = [...array1, ...array2, ...array3]


          Looping through the items and then putting the values to "object"



          let object = 
          array.forEach((item) =>
          object[item.id] = ...object[item.id],...item)


          Final solution



          result = Object.values(object)


          object variable will contain



          object = '1': id: 1, age: 20, name: 'raju', degree: 'b.com' ,
          '2': id: 2, name: 'ravi' ,
          '3': id: 3, age: 21, degree: 'b.a' ,
          '4': id: 4, degree: 'c.a', name: 'john' ,
          '5': id: 5, degree: 'horticulture' ,
          '6': id: 6, age: 27, name: 'jack' ,
          '7': id: 7, age: 25


          result variable will contain



          result = [ id: 1, age: 20, name: 'raju', degree: 'b.com' ,
          id: 2, name: 'ravi' ,
          id: 3, age: 21, degree: 'b.a' ,
          id: 4, degree: 'c.a', name: 'john' ,
          id: 5, degree: 'horticulture' ,
          id: 6, age: 27, name: 'jack' ,
          id: 7, age: 25 ]





          share|improve this answer




















          • 1





            Oh by the i was adding this solution, 2 people have already solved and posted their answers :)

            – pavan skipo
            Mar 22 at 5:14











          • can we keep this result array as a child to one parent id(another different id )

            – Phani Kumar Devu
            Mar 22 at 5:17






          • 1





            yeah we can it is a list of objects. wait ill update the answer

            – pavan skipo
            Mar 22 at 5:21











          • i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

            – Phani Kumar Devu
            Mar 22 at 5:27













          1












          1








          1







          There will be better solutions than this, but this is what I've tried:



          Merging the 3 arrays into one :



          let array = [...array1, ...array2, ...array3]


          Looping through the items and then putting the values to "object"



          let object = 
          array.forEach((item) =>
          object[item.id] = ...object[item.id],...item)


          Final solution



          result = Object.values(object)


          object variable will contain



          object = '1': id: 1, age: 20, name: 'raju', degree: 'b.com' ,
          '2': id: 2, name: 'ravi' ,
          '3': id: 3, age: 21, degree: 'b.a' ,
          '4': id: 4, degree: 'c.a', name: 'john' ,
          '5': id: 5, degree: 'horticulture' ,
          '6': id: 6, age: 27, name: 'jack' ,
          '7': id: 7, age: 25


          result variable will contain



          result = [ id: 1, age: 20, name: 'raju', degree: 'b.com' ,
          id: 2, name: 'ravi' ,
          id: 3, age: 21, degree: 'b.a' ,
          id: 4, degree: 'c.a', name: 'john' ,
          id: 5, degree: 'horticulture' ,
          id: 6, age: 27, name: 'jack' ,
          id: 7, age: 25 ]





          share|improve this answer















          There will be better solutions than this, but this is what I've tried:



          Merging the 3 arrays into one :



          let array = [...array1, ...array2, ...array3]


          Looping through the items and then putting the values to "object"



          let object = 
          array.forEach((item) =>
          object[item.id] = ...object[item.id],...item)


          Final solution



          result = Object.values(object)


          object variable will contain



          object = '1': id: 1, age: 20, name: 'raju', degree: 'b.com' ,
          '2': id: 2, name: 'ravi' ,
          '3': id: 3, age: 21, degree: 'b.a' ,
          '4': id: 4, degree: 'c.a', name: 'john' ,
          '5': id: 5, degree: 'horticulture' ,
          '6': id: 6, age: 27, name: 'jack' ,
          '7': id: 7, age: 25


          result variable will contain



          result = [ id: 1, age: 20, name: 'raju', degree: 'b.com' ,
          id: 2, name: 'ravi' ,
          id: 3, age: 21, degree: 'b.a' ,
          id: 4, degree: 'c.a', name: 'john' ,
          id: 5, degree: 'horticulture' ,
          id: 6, age: 27, name: 'jack' ,
          id: 7, age: 25 ]






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 22 at 5:23

























          answered Mar 22 at 5:13









          pavan skipopavan skipo

          531115




          531115







          • 1





            Oh by the i was adding this solution, 2 people have already solved and posted their answers :)

            – pavan skipo
            Mar 22 at 5:14











          • can we keep this result array as a child to one parent id(another different id )

            – Phani Kumar Devu
            Mar 22 at 5:17






          • 1





            yeah we can it is a list of objects. wait ill update the answer

            – pavan skipo
            Mar 22 at 5:21











          • i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

            – Phani Kumar Devu
            Mar 22 at 5:27












          • 1





            Oh by the i was adding this solution, 2 people have already solved and posted their answers :)

            – pavan skipo
            Mar 22 at 5:14











          • can we keep this result array as a child to one parent id(another different id )

            – Phani Kumar Devu
            Mar 22 at 5:17






          • 1





            yeah we can it is a list of objects. wait ill update the answer

            – pavan skipo
            Mar 22 at 5:21











          • i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

            – Phani Kumar Devu
            Mar 22 at 5:27







          1




          1





          Oh by the i was adding this solution, 2 people have already solved and posted their answers :)

          – pavan skipo
          Mar 22 at 5:14





          Oh by the i was adding this solution, 2 people have already solved and posted their answers :)

          – pavan skipo
          Mar 22 at 5:14













          can we keep this result array as a child to one parent id(another different id )

          – Phani Kumar Devu
          Mar 22 at 5:17





          can we keep this result array as a child to one parent id(another different id )

          – Phani Kumar Devu
          Mar 22 at 5:17




          1




          1





          yeah we can it is a list of objects. wait ill update the answer

          – pavan skipo
          Mar 22 at 5:21





          yeah we can it is a list of objects. wait ill update the answer

          – pavan skipo
          Mar 22 at 5:21













          i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

          – Phani Kumar Devu
          Mar 22 at 5:27





          i mean there will one more id like UserID: 201, Userrating:resultarray here UserID is parent and Userrating is child..

          – Phani Kumar Devu
          Mar 22 at 5:27

















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55293036%2fhow-to-merge-three-different-arrays-by-comparing-with-id-in-angular-6%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

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript