Push items in objects from array when matchCreate ArrayList from arrayHow do I check if an array includes an object in JavaScript?Deleting an element from an array in PHPHow to insert an item into an array at a specific index (JavaScript)?Sorting an array of JavaScript objects by propertySort array of objects by string property valueHow to merge two arrays in JavaScript and de-duplicate itemsCopy array items into another arrayHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?

Is Chuck the Evil Sandwich Making Guy's head actually a sandwich?

Doesn't the concept of marginal utility speak to a cardinal utility function?

Why do modes sound so different, although they are basically the same as a mode of another scale?

Pandas transform inconsistent behavior for list

Missing $ inserted. Extra }, or forgotten $. Missing } inserted

Why do motor drives have multiple bus capacitors of small value capacitance instead of a single bus capacitor of large value?

Quick Slitherlink Puzzles: KPK and 123

How were US credit cards verified in-store in the 1980's?

Why is Mitch McConnell blocking nominees to the Federal Election Commission?

Does the telecom provider need physical access to the SIM card to clone it?

To minimize the Hausdorff distance between convex polygonal regions

What happens if you just start drawing from the Deck of Many Things without declaring any number of cards?

Fishing from underwater domes

D Scale Question

What is causing gaps in logs?

How does the search space affect the speed of an ILP solver?

How to have the "Restore Missing Files" function from Nautilus without installing Nautilus?

What is the motivation behind designing a control stick that does not move?

Can authors email you PDFs of their textbook for free?

Why are CEOs generally fired rather being demoted?

Could a simple hospital oxygen mask protect from aerosol poison?

Am I required to correct my opponent's assumptions about my morph creatures?

How could reincarnation magic be limited to prevent overuse?

Why do fuses burn at a specific current?



Push items in objects from array when match


Create ArrayList from arrayHow do I check if an array includes an object in JavaScript?Deleting an element from an array in PHPHow to insert an item into an array at a specific index (JavaScript)?Sorting an array of JavaScript objects by propertySort array of objects by string property valueHow to merge two arrays in JavaScript and de-duplicate itemsCopy array items into another arrayHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I have an array and object of items, I want to check each item in that array if its path has that object name, I push it in that object array.



So far this is all good, now if no match found I want to create a new item based on that array item name and push it inside it!



All my attempts ending in duplicated value, I think I need a third object/array I just can't think it anymore



To explain better:



cList = 
"rList":
"Significant": [

"Path": "Significant\Significant Charts",
"Name": "Charts"

]
,
;


and



SSList = 
value: [

"Name": "Test long name",
"Path": "/someFolder/Test long name",
,

"Name": "Untitled",
"Path": "/Significant/Untitled",

]
;


My current code



for (var cFolder in this.cList.rList) 
this.SSList.forEach((ssFile)=>
if(ssFile.Path.indexOf(cFolder) >= 0)
this.cList.rList[cFolder].push(ssFile);

);



The first item in SSList will not be pushed since it doesn't match, I want to create a array and push it to inside rList



var folderName = ssFile.Path.split("/");
this.cList.rList[folderName[1]].push(ssFile);









share|improve this question






























    1















    I have an array and object of items, I want to check each item in that array if its path has that object name, I push it in that object array.



    So far this is all good, now if no match found I want to create a new item based on that array item name and push it inside it!



    All my attempts ending in duplicated value, I think I need a third object/array I just can't think it anymore



    To explain better:



    cList = 
    "rList":
    "Significant": [

    "Path": "Significant\Significant Charts",
    "Name": "Charts"

    ]
    ,
    ;


    and



    SSList = 
    value: [

    "Name": "Test long name",
    "Path": "/someFolder/Test long name",
    ,

    "Name": "Untitled",
    "Path": "/Significant/Untitled",

    ]
    ;


    My current code



    for (var cFolder in this.cList.rList) 
    this.SSList.forEach((ssFile)=>
    if(ssFile.Path.indexOf(cFolder) >= 0)
    this.cList.rList[cFolder].push(ssFile);

    );



    The first item in SSList will not be pushed since it doesn't match, I want to create a array and push it to inside rList



    var folderName = ssFile.Path.split("/");
    this.cList.rList[folderName[1]].push(ssFile);









    share|improve this question


























      1












      1








      1








      I have an array and object of items, I want to check each item in that array if its path has that object name, I push it in that object array.



      So far this is all good, now if no match found I want to create a new item based on that array item name and push it inside it!



      All my attempts ending in duplicated value, I think I need a third object/array I just can't think it anymore



      To explain better:



      cList = 
      "rList":
      "Significant": [

      "Path": "Significant\Significant Charts",
      "Name": "Charts"

      ]
      ,
      ;


      and



      SSList = 
      value: [

      "Name": "Test long name",
      "Path": "/someFolder/Test long name",
      ,

      "Name": "Untitled",
      "Path": "/Significant/Untitled",

      ]
      ;


      My current code



      for (var cFolder in this.cList.rList) 
      this.SSList.forEach((ssFile)=>
      if(ssFile.Path.indexOf(cFolder) >= 0)
      this.cList.rList[cFolder].push(ssFile);

      );



      The first item in SSList will not be pushed since it doesn't match, I want to create a array and push it to inside rList



      var folderName = ssFile.Path.split("/");
      this.cList.rList[folderName[1]].push(ssFile);









      share|improve this question














      I have an array and object of items, I want to check each item in that array if its path has that object name, I push it in that object array.



      So far this is all good, now if no match found I want to create a new item based on that array item name and push it inside it!



      All my attempts ending in duplicated value, I think I need a third object/array I just can't think it anymore



      To explain better:



      cList = 
      "rList":
      "Significant": [

      "Path": "Significant\Significant Charts",
      "Name": "Charts"

      ]
      ,
      ;


      and



      SSList = 
      value: [

      "Name": "Test long name",
      "Path": "/someFolder/Test long name",
      ,

      "Name": "Untitled",
      "Path": "/Significant/Untitled",

      ]
      ;


      My current code



      for (var cFolder in this.cList.rList) 
      this.SSList.forEach((ssFile)=>
      if(ssFile.Path.indexOf(cFolder) >= 0)
      this.cList.rList[cFolder].push(ssFile);

      );



      The first item in SSList will not be pushed since it doesn't match, I want to create a array and push it to inside rList



      var folderName = ssFile.Path.split("/");
      this.cList.rList[folderName[1]].push(ssFile);






      arrays angular typescript sorting merge






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 28 at 0:30









      et3rnalet3rnal

      1102 silver badges11 bronze badges




      1102 silver badges11 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          1















          One way to do it is to flip your inner and outer loops



          let found = false;
          this.SSList.value.forEach((ssFile) =>
          for (var cFolder in this.cList.rList)
          if(ssFile.Path.indexOf(cFolder) >= 0)
          found = true;
          break;


          if (found)
          this.cList.rList[cFolder].push(ssFile);
          else
          folderName = ssFile.Path.split("/");
          if (!(folderName[1] in this.cList.rList))
          this.cList.rList[folderName[1]] = [];
          this.cList.rList[folderName[1]].push(ssFile);

          found = false;
          );





          share|improve this answer



























          • Just perfect. Thanks, heaps

            – et3rnal
            Mar 28 at 4:03










          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%2f55388464%2fpush-items-in-objects-from-array-when-match%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1















          One way to do it is to flip your inner and outer loops



          let found = false;
          this.SSList.value.forEach((ssFile) =>
          for (var cFolder in this.cList.rList)
          if(ssFile.Path.indexOf(cFolder) >= 0)
          found = true;
          break;


          if (found)
          this.cList.rList[cFolder].push(ssFile);
          else
          folderName = ssFile.Path.split("/");
          if (!(folderName[1] in this.cList.rList))
          this.cList.rList[folderName[1]] = [];
          this.cList.rList[folderName[1]].push(ssFile);

          found = false;
          );





          share|improve this answer



























          • Just perfect. Thanks, heaps

            – et3rnal
            Mar 28 at 4:03















          1















          One way to do it is to flip your inner and outer loops



          let found = false;
          this.SSList.value.forEach((ssFile) =>
          for (var cFolder in this.cList.rList)
          if(ssFile.Path.indexOf(cFolder) >= 0)
          found = true;
          break;


          if (found)
          this.cList.rList[cFolder].push(ssFile);
          else
          folderName = ssFile.Path.split("/");
          if (!(folderName[1] in this.cList.rList))
          this.cList.rList[folderName[1]] = [];
          this.cList.rList[folderName[1]].push(ssFile);

          found = false;
          );





          share|improve this answer



























          • Just perfect. Thanks, heaps

            – et3rnal
            Mar 28 at 4:03













          1














          1










          1









          One way to do it is to flip your inner and outer loops



          let found = false;
          this.SSList.value.forEach((ssFile) =>
          for (var cFolder in this.cList.rList)
          if(ssFile.Path.indexOf(cFolder) >= 0)
          found = true;
          break;


          if (found)
          this.cList.rList[cFolder].push(ssFile);
          else
          folderName = ssFile.Path.split("/");
          if (!(folderName[1] in this.cList.rList))
          this.cList.rList[folderName[1]] = [];
          this.cList.rList[folderName[1]].push(ssFile);

          found = false;
          );





          share|improve this answer















          One way to do it is to flip your inner and outer loops



          let found = false;
          this.SSList.value.forEach((ssFile) =>
          for (var cFolder in this.cList.rList)
          if(ssFile.Path.indexOf(cFolder) >= 0)
          found = true;
          break;


          if (found)
          this.cList.rList[cFolder].push(ssFile);
          else
          folderName = ssFile.Path.split("/");
          if (!(folderName[1] in this.cList.rList))
          this.cList.rList[folderName[1]] = [];
          this.cList.rList[folderName[1]].push(ssFile);

          found = false;
          );






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 28 at 2:44

























          answered Mar 28 at 2:35









          SaharshSaharsh

          6666 silver badges17 bronze badges




          6666 silver badges17 bronze badges















          • Just perfect. Thanks, heaps

            – et3rnal
            Mar 28 at 4:03

















          • Just perfect. Thanks, heaps

            – et3rnal
            Mar 28 at 4:03
















          Just perfect. Thanks, heaps

          – et3rnal
          Mar 28 at 4:03





          Just perfect. Thanks, heaps

          – et3rnal
          Mar 28 at 4:03








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          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%2f55388464%2fpush-items-in-objects-from-array-when-match%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

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현