Remove object from array based on array of some property of that object2019 Community Moderator ElectionIs the Set.has() method O(1) and Array.indexOf O(n)?Detecting an undefined object propertyCreate ArrayList from arrayHow can I merge properties of two JavaScript objects dynamically?How do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?PHP: Delete an element from an arraySort array of objects by string property valueHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?Iterate through object properties

Touchscreen-controlled dentist office snowman collector game

Best approach to update all entries in a list that is paginated?

Can the druid cantrip Thorn Whip really defeat a water weird this easily?

Replacing Windows 7 security updates with anti-virus?

What wound would be of little consequence to a biped but terrible for a quadruped?

Single word request: Harming the benefactor

How to make readers know that my work has used a hidden constraint?

What happens with multiple copies of Humility and Glorious Anthem on the battlefield?

Should QA ask requirements to developers?

When two POV characters meet

Is it ok to include an epilogue dedicated to colleagues who passed away in the end of the manuscript?

Can "semicircle" be used to refer to a part-circle that is not a exact half-circle?

Is having access to past exams cheating and, if yes, could it be proven just by a good grade?

Make a transparent 448*448 image

Why does Deadpool say "You're welcome, Canada," after shooting Ryan Reynolds in the end credits?

Do I need to leave some extra space available on the disk which my database log files reside, for log backup operations to successfully occur?

Who is our nearest neighbor

What is the difference between "shut" and "close"?

Time travel short story where dinosaur doesn't taste like chicken

Good allowance savings plan?

Straight line with arrows and dots

When were linguistics departments first established

Life insurance that covers only simultaneous/dual deaths

Ban on all campaign finance?



Remove object from array based on array of some property of that object



2019 Community Moderator ElectionIs the Set.has() method O(1) and Array.indexOf O(n)?Detecting an undefined object propertyCreate ArrayList from arrayHow can I merge properties of two JavaScript objects dynamically?How do I remove a property from a JavaScript object?How do I check if an array includes an object in JavaScript?PHP: Delete an element from an arraySort array of objects by string property valueHow to check if an object is an array?How do I remove a particular element from an array in JavaScript?Iterate through object properties










17















I have an array of objects (objList) that each has "id" property.



I have an array of strings (idsToRemove), representing IDs of the objects to remove from objList.



I find some solution but I fear it's slow, especially with the large list of objects with lots of properties.
Is there more efficient way to do this?






var idsToRemove = ["3", "1"];
var objList = [
id: "1",
name: "aaa"
,

id: "2",
name: "bbb"
,

id: "3",
name: "ccc"

];

for (var i = 0, len = idsToRemove.length; i < len; i++)
objList = objList.filter(o => o.id != idsToRemove[i]);


console.log(objList);












share|improve this question




























    17















    I have an array of objects (objList) that each has "id" property.



    I have an array of strings (idsToRemove), representing IDs of the objects to remove from objList.



    I find some solution but I fear it's slow, especially with the large list of objects with lots of properties.
    Is there more efficient way to do this?






    var idsToRemove = ["3", "1"];
    var objList = [
    id: "1",
    name: "aaa"
    ,

    id: "2",
    name: "bbb"
    ,

    id: "3",
    name: "ccc"

    ];

    for (var i = 0, len = idsToRemove.length; i < len; i++)
    objList = objList.filter(o => o.id != idsToRemove[i]);


    console.log(objList);












    share|improve this question


























      17












      17








      17








      I have an array of objects (objList) that each has "id" property.



      I have an array of strings (idsToRemove), representing IDs of the objects to remove from objList.



      I find some solution but I fear it's slow, especially with the large list of objects with lots of properties.
      Is there more efficient way to do this?






      var idsToRemove = ["3", "1"];
      var objList = [
      id: "1",
      name: "aaa"
      ,

      id: "2",
      name: "bbb"
      ,

      id: "3",
      name: "ccc"

      ];

      for (var i = 0, len = idsToRemove.length; i < len; i++)
      objList = objList.filter(o => o.id != idsToRemove[i]);


      console.log(objList);












      share|improve this question
















      I have an array of objects (objList) that each has "id" property.



      I have an array of strings (idsToRemove), representing IDs of the objects to remove from objList.



      I find some solution but I fear it's slow, especially with the large list of objects with lots of properties.
      Is there more efficient way to do this?






      var idsToRemove = ["3", "1"];
      var objList = [
      id: "1",
      name: "aaa"
      ,

      id: "2",
      name: "bbb"
      ,

      id: "3",
      name: "ccc"

      ];

      for (var i = 0, len = idsToRemove.length; i < len; i++)
      objList = objList.filter(o => o.id != idsToRemove[i]);


      console.log(objList);








      var idsToRemove = ["3", "1"];
      var objList = [
      id: "1",
      name: "aaa"
      ,

      id: "2",
      name: "bbb"
      ,

      id: "3",
      name: "ccc"

      ];

      for (var i = 0, len = idsToRemove.length; i < len; i++)
      objList = objList.filter(o => o.id != idsToRemove[i]);


      console.log(objList);





      var idsToRemove = ["3", "1"];
      var objList = [
      id: "1",
      name: "aaa"
      ,

      id: "2",
      name: "bbb"
      ,

      id: "3",
      name: "ccc"

      ];

      for (var i = 0, len = idsToRemove.length; i < len; i++)
      objList = objList.filter(o => o.id != idsToRemove[i]);


      console.log(objList);






      javascript arrays performance






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 7 at 12:52









      Uwe Keim

      27.6k32132214




      27.6k32132214










      asked Mar 7 at 10:48









      DaliborDalibor

      513318




      513318






















          4 Answers
          4






          active

          oldest

          votes


















          34














          Turn the idsToRemove into a Set so that you can use Set.prototype.has (an O(1) operation), and .filter the objList just once, so that the overall complexity is O(n) (and you only iterate over the possibly-huge objList once):






          var idsToRemove = ["3", "1"];
          var objList = [
          id: "1",
          name: "aaa"
          ,

          id: "2",
          name: "bbb"
          ,

          id: "3",
          name: "ccc"

          ];

          const set = new Set(idsToRemove);
          const filtered = objList.filter(( id ) => !set.has(id));
          console.log(filtered);





          Note that Array.prototype.includes and Array.prototype.indexOf operations are O(N), not O(1), so if you use them instead of a Set, they may take significantly longer.






          share|improve this answer

























          • Not sure if the claim Set.has is O(1) is correct. Please provide an answer to this question if it is correct. stackoverflow.com/questions/55057200/…

            – Charlie H
            Mar 8 at 5:55












          • Does it not depend on the size of the array? If the array is small, is it not better to through it than creating a new copy in memory then access it ?

            – Grégory NEUT
            Mar 8 at 7:58






          • 1





            You're right, if the idsToRemove has a very small number of elements, using a Set instead doesn't provide much of a benefit.

            – CertainPerformance
            Mar 8 at 8:31











          • Can you explain me the difference between your syntax and this syntax: const filtered = objList.filter(o => !set.has(o.id));

            – Dalibor
            Mar 9 at 11:42






          • 1





            @Dalibor My version uses destructuring in the argument list, whereas that version doesn't. If a function doesn't need the whole object, but only one (or some) of its properties, I like to extract that property immediately rather than having to hold on to the whole object - but both options work just fine.

            – CertainPerformance
            Mar 9 at 11:48


















          4














          You can use Array.includes which check if the given string exists in the given array and combine it with an Array.filter.






          const idsToRemove = ['3', '1'];

          const objList = [
          id: '1',
          name: 'aaa',
          ,

          id: '2',
          name: 'bbb',
          ,

          id: '3',
          name: 'ccc',
          ,
          ];

          const filteredObjList = objList.filter(x => !idsToRemove.includes(x.id));

          console.log(filteredObjList);








          share|improve this answer






























            2














            You don't need two nested iterators if you use a built-in lookup function



             objList = objList.filter(o => idsToRemove.indexOf(o.id) < 0);


            Documentation:



            Array.prototype.indexOf()



            Array.prototype.includes()






            share|improve this answer
































              1














              Simply use Array.filter()




              const idsToRemove = ['3', '1'];

              const objList = [
              id: '1',
              name: 'aaa',
              ,

              id: '2',
              name: 'bbb',
              ,

              id: '3',
              name: 'ccc',

              ];

              const res = objList.filter(value => !idsToRemove.includes(value.id));

              console.log("result",res);








              share|improve this answer
























                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%2f55041973%2fremove-object-from-array-based-on-array-of-some-property-of-that-object%23new-answer', 'question_page');

                );

                Post as a guest















                Required, but never shown

























                4 Answers
                4






                active

                oldest

                votes








                4 Answers
                4






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                34














                Turn the idsToRemove into a Set so that you can use Set.prototype.has (an O(1) operation), and .filter the objList just once, so that the overall complexity is O(n) (and you only iterate over the possibly-huge objList once):






                var idsToRemove = ["3", "1"];
                var objList = [
                id: "1",
                name: "aaa"
                ,

                id: "2",
                name: "bbb"
                ,

                id: "3",
                name: "ccc"

                ];

                const set = new Set(idsToRemove);
                const filtered = objList.filter(( id ) => !set.has(id));
                console.log(filtered);





                Note that Array.prototype.includes and Array.prototype.indexOf operations are O(N), not O(1), so if you use them instead of a Set, they may take significantly longer.






                share|improve this answer

























                • Not sure if the claim Set.has is O(1) is correct. Please provide an answer to this question if it is correct. stackoverflow.com/questions/55057200/…

                  – Charlie H
                  Mar 8 at 5:55












                • Does it not depend on the size of the array? If the array is small, is it not better to through it than creating a new copy in memory then access it ?

                  – Grégory NEUT
                  Mar 8 at 7:58






                • 1





                  You're right, if the idsToRemove has a very small number of elements, using a Set instead doesn't provide much of a benefit.

                  – CertainPerformance
                  Mar 8 at 8:31











                • Can you explain me the difference between your syntax and this syntax: const filtered = objList.filter(o => !set.has(o.id));

                  – Dalibor
                  Mar 9 at 11:42






                • 1





                  @Dalibor My version uses destructuring in the argument list, whereas that version doesn't. If a function doesn't need the whole object, but only one (or some) of its properties, I like to extract that property immediately rather than having to hold on to the whole object - but both options work just fine.

                  – CertainPerformance
                  Mar 9 at 11:48















                34














                Turn the idsToRemove into a Set so that you can use Set.prototype.has (an O(1) operation), and .filter the objList just once, so that the overall complexity is O(n) (and you only iterate over the possibly-huge objList once):






                var idsToRemove = ["3", "1"];
                var objList = [
                id: "1",
                name: "aaa"
                ,

                id: "2",
                name: "bbb"
                ,

                id: "3",
                name: "ccc"

                ];

                const set = new Set(idsToRemove);
                const filtered = objList.filter(( id ) => !set.has(id));
                console.log(filtered);





                Note that Array.prototype.includes and Array.prototype.indexOf operations are O(N), not O(1), so if you use them instead of a Set, they may take significantly longer.






                share|improve this answer

























                • Not sure if the claim Set.has is O(1) is correct. Please provide an answer to this question if it is correct. stackoverflow.com/questions/55057200/…

                  – Charlie H
                  Mar 8 at 5:55












                • Does it not depend on the size of the array? If the array is small, is it not better to through it than creating a new copy in memory then access it ?

                  – Grégory NEUT
                  Mar 8 at 7:58






                • 1





                  You're right, if the idsToRemove has a very small number of elements, using a Set instead doesn't provide much of a benefit.

                  – CertainPerformance
                  Mar 8 at 8:31











                • Can you explain me the difference between your syntax and this syntax: const filtered = objList.filter(o => !set.has(o.id));

                  – Dalibor
                  Mar 9 at 11:42






                • 1





                  @Dalibor My version uses destructuring in the argument list, whereas that version doesn't. If a function doesn't need the whole object, but only one (or some) of its properties, I like to extract that property immediately rather than having to hold on to the whole object - but both options work just fine.

                  – CertainPerformance
                  Mar 9 at 11:48













                34












                34








                34







                Turn the idsToRemove into a Set so that you can use Set.prototype.has (an O(1) operation), and .filter the objList just once, so that the overall complexity is O(n) (and you only iterate over the possibly-huge objList once):






                var idsToRemove = ["3", "1"];
                var objList = [
                id: "1",
                name: "aaa"
                ,

                id: "2",
                name: "bbb"
                ,

                id: "3",
                name: "ccc"

                ];

                const set = new Set(idsToRemove);
                const filtered = objList.filter(( id ) => !set.has(id));
                console.log(filtered);





                Note that Array.prototype.includes and Array.prototype.indexOf operations are O(N), not O(1), so if you use them instead of a Set, they may take significantly longer.






                share|improve this answer















                Turn the idsToRemove into a Set so that you can use Set.prototype.has (an O(1) operation), and .filter the objList just once, so that the overall complexity is O(n) (and you only iterate over the possibly-huge objList once):






                var idsToRemove = ["3", "1"];
                var objList = [
                id: "1",
                name: "aaa"
                ,

                id: "2",
                name: "bbb"
                ,

                id: "3",
                name: "ccc"

                ];

                const set = new Set(idsToRemove);
                const filtered = objList.filter(( id ) => !set.has(id));
                console.log(filtered);





                Note that Array.prototype.includes and Array.prototype.indexOf operations are O(N), not O(1), so if you use them instead of a Set, they may take significantly longer.






                var idsToRemove = ["3", "1"];
                var objList = [
                id: "1",
                name: "aaa"
                ,

                id: "2",
                name: "bbb"
                ,

                id: "3",
                name: "ccc"

                ];

                const set = new Set(idsToRemove);
                const filtered = objList.filter(( id ) => !set.has(id));
                console.log(filtered);





                var idsToRemove = ["3", "1"];
                var objList = [
                id: "1",
                name: "aaa"
                ,

                id: "2",
                name: "bbb"
                ,

                id: "3",
                name: "ccc"

                ];

                const set = new Set(idsToRemove);
                const filtered = objList.filter(( id ) => !set.has(id));
                console.log(filtered);






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 7 at 11:03

























                answered Mar 7 at 10:51









                CertainPerformanceCertainPerformance

                92.9k165384




                92.9k165384












                • Not sure if the claim Set.has is O(1) is correct. Please provide an answer to this question if it is correct. stackoverflow.com/questions/55057200/…

                  – Charlie H
                  Mar 8 at 5:55












                • Does it not depend on the size of the array? If the array is small, is it not better to through it than creating a new copy in memory then access it ?

                  – Grégory NEUT
                  Mar 8 at 7:58






                • 1





                  You're right, if the idsToRemove has a very small number of elements, using a Set instead doesn't provide much of a benefit.

                  – CertainPerformance
                  Mar 8 at 8:31











                • Can you explain me the difference between your syntax and this syntax: const filtered = objList.filter(o => !set.has(o.id));

                  – Dalibor
                  Mar 9 at 11:42






                • 1





                  @Dalibor My version uses destructuring in the argument list, whereas that version doesn't. If a function doesn't need the whole object, but only one (or some) of its properties, I like to extract that property immediately rather than having to hold on to the whole object - but both options work just fine.

                  – CertainPerformance
                  Mar 9 at 11:48

















                • Not sure if the claim Set.has is O(1) is correct. Please provide an answer to this question if it is correct. stackoverflow.com/questions/55057200/…

                  – Charlie H
                  Mar 8 at 5:55












                • Does it not depend on the size of the array? If the array is small, is it not better to through it than creating a new copy in memory then access it ?

                  – Grégory NEUT
                  Mar 8 at 7:58






                • 1





                  You're right, if the idsToRemove has a very small number of elements, using a Set instead doesn't provide much of a benefit.

                  – CertainPerformance
                  Mar 8 at 8:31











                • Can you explain me the difference between your syntax and this syntax: const filtered = objList.filter(o => !set.has(o.id));

                  – Dalibor
                  Mar 9 at 11:42






                • 1





                  @Dalibor My version uses destructuring in the argument list, whereas that version doesn't. If a function doesn't need the whole object, but only one (or some) of its properties, I like to extract that property immediately rather than having to hold on to the whole object - but both options work just fine.

                  – CertainPerformance
                  Mar 9 at 11:48
















                Not sure if the claim Set.has is O(1) is correct. Please provide an answer to this question if it is correct. stackoverflow.com/questions/55057200/…

                – Charlie H
                Mar 8 at 5:55






                Not sure if the claim Set.has is O(1) is correct. Please provide an answer to this question if it is correct. stackoverflow.com/questions/55057200/…

                – Charlie H
                Mar 8 at 5:55














                Does it not depend on the size of the array? If the array is small, is it not better to through it than creating a new copy in memory then access it ?

                – Grégory NEUT
                Mar 8 at 7:58





                Does it not depend on the size of the array? If the array is small, is it not better to through it than creating a new copy in memory then access it ?

                – Grégory NEUT
                Mar 8 at 7:58




                1




                1





                You're right, if the idsToRemove has a very small number of elements, using a Set instead doesn't provide much of a benefit.

                – CertainPerformance
                Mar 8 at 8:31





                You're right, if the idsToRemove has a very small number of elements, using a Set instead doesn't provide much of a benefit.

                – CertainPerformance
                Mar 8 at 8:31













                Can you explain me the difference between your syntax and this syntax: const filtered = objList.filter(o => !set.has(o.id));

                – Dalibor
                Mar 9 at 11:42





                Can you explain me the difference between your syntax and this syntax: const filtered = objList.filter(o => !set.has(o.id));

                – Dalibor
                Mar 9 at 11:42




                1




                1





                @Dalibor My version uses destructuring in the argument list, whereas that version doesn't. If a function doesn't need the whole object, but only one (or some) of its properties, I like to extract that property immediately rather than having to hold on to the whole object - but both options work just fine.

                – CertainPerformance
                Mar 9 at 11:48





                @Dalibor My version uses destructuring in the argument list, whereas that version doesn't. If a function doesn't need the whole object, but only one (or some) of its properties, I like to extract that property immediately rather than having to hold on to the whole object - but both options work just fine.

                – CertainPerformance
                Mar 9 at 11:48













                4














                You can use Array.includes which check if the given string exists in the given array and combine it with an Array.filter.






                const idsToRemove = ['3', '1'];

                const objList = [
                id: '1',
                name: 'aaa',
                ,

                id: '2',
                name: 'bbb',
                ,

                id: '3',
                name: 'ccc',
                ,
                ];

                const filteredObjList = objList.filter(x => !idsToRemove.includes(x.id));

                console.log(filteredObjList);








                share|improve this answer



























                  4














                  You can use Array.includes which check if the given string exists in the given array and combine it with an Array.filter.






                  const idsToRemove = ['3', '1'];

                  const objList = [
                  id: '1',
                  name: 'aaa',
                  ,

                  id: '2',
                  name: 'bbb',
                  ,

                  id: '3',
                  name: 'ccc',
                  ,
                  ];

                  const filteredObjList = objList.filter(x => !idsToRemove.includes(x.id));

                  console.log(filteredObjList);








                  share|improve this answer

























                    4












                    4








                    4







                    You can use Array.includes which check if the given string exists in the given array and combine it with an Array.filter.






                    const idsToRemove = ['3', '1'];

                    const objList = [
                    id: '1',
                    name: 'aaa',
                    ,

                    id: '2',
                    name: 'bbb',
                    ,

                    id: '3',
                    name: 'ccc',
                    ,
                    ];

                    const filteredObjList = objList.filter(x => !idsToRemove.includes(x.id));

                    console.log(filteredObjList);








                    share|improve this answer













                    You can use Array.includes which check if the given string exists in the given array and combine it with an Array.filter.






                    const idsToRemove = ['3', '1'];

                    const objList = [
                    id: '1',
                    name: 'aaa',
                    ,

                    id: '2',
                    name: 'bbb',
                    ,

                    id: '3',
                    name: 'ccc',
                    ,
                    ];

                    const filteredObjList = objList.filter(x => !idsToRemove.includes(x.id));

                    console.log(filteredObjList);








                    const idsToRemove = ['3', '1'];

                    const objList = [
                    id: '1',
                    name: 'aaa',
                    ,

                    id: '2',
                    name: 'bbb',
                    ,

                    id: '3',
                    name: 'ccc',
                    ,
                    ];

                    const filteredObjList = objList.filter(x => !idsToRemove.includes(x.id));

                    console.log(filteredObjList);





                    const idsToRemove = ['3', '1'];

                    const objList = [
                    id: '1',
                    name: 'aaa',
                    ,

                    id: '2',
                    name: 'bbb',
                    ,

                    id: '3',
                    name: 'ccc',
                    ,
                    ];

                    const filteredObjList = objList.filter(x => !idsToRemove.includes(x.id));

                    console.log(filteredObjList);






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 7 at 10:55









                    Grégory NEUTGrégory NEUT

                    9,58721941




                    9,58721941





















                        2














                        You don't need two nested iterators if you use a built-in lookup function



                         objList = objList.filter(o => idsToRemove.indexOf(o.id) < 0);


                        Documentation:



                        Array.prototype.indexOf()



                        Array.prototype.includes()






                        share|improve this answer





























                          2














                          You don't need two nested iterators if you use a built-in lookup function



                           objList = objList.filter(o => idsToRemove.indexOf(o.id) < 0);


                          Documentation:



                          Array.prototype.indexOf()



                          Array.prototype.includes()






                          share|improve this answer



























                            2












                            2








                            2







                            You don't need two nested iterators if you use a built-in lookup function



                             objList = objList.filter(o => idsToRemove.indexOf(o.id) < 0);


                            Documentation:



                            Array.prototype.indexOf()



                            Array.prototype.includes()






                            share|improve this answer















                            You don't need two nested iterators if you use a built-in lookup function



                             objList = objList.filter(o => idsToRemove.indexOf(o.id) < 0);


                            Documentation:



                            Array.prototype.indexOf()



                            Array.prototype.includes()







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Mar 7 at 11:08

























                            answered Mar 7 at 10:54









                            Charlie HCharlie H

                            9,56342653




                            9,56342653





















                                1














                                Simply use Array.filter()




                                const idsToRemove = ['3', '1'];

                                const objList = [
                                id: '1',
                                name: 'aaa',
                                ,

                                id: '2',
                                name: 'bbb',
                                ,

                                id: '3',
                                name: 'ccc',

                                ];

                                const res = objList.filter(value => !idsToRemove.includes(value.id));

                                console.log("result",res);








                                share|improve this answer





























                                  1














                                  Simply use Array.filter()




                                  const idsToRemove = ['3', '1'];

                                  const objList = [
                                  id: '1',
                                  name: 'aaa',
                                  ,

                                  id: '2',
                                  name: 'bbb',
                                  ,

                                  id: '3',
                                  name: 'ccc',

                                  ];

                                  const res = objList.filter(value => !idsToRemove.includes(value.id));

                                  console.log("result",res);








                                  share|improve this answer



























                                    1












                                    1








                                    1







                                    Simply use Array.filter()




                                    const idsToRemove = ['3', '1'];

                                    const objList = [
                                    id: '1',
                                    name: 'aaa',
                                    ,

                                    id: '2',
                                    name: 'bbb',
                                    ,

                                    id: '3',
                                    name: 'ccc',

                                    ];

                                    const res = objList.filter(value => !idsToRemove.includes(value.id));

                                    console.log("result",res);








                                    share|improve this answer















                                    Simply use Array.filter()




                                    const idsToRemove = ['3', '1'];

                                    const objList = [
                                    id: '1',
                                    name: 'aaa',
                                    ,

                                    id: '2',
                                    name: 'bbb',
                                    ,

                                    id: '3',
                                    name: 'ccc',

                                    ];

                                    const res = objList.filter(value => !idsToRemove.includes(value.id));

                                    console.log("result",res);








                                    const idsToRemove = ['3', '1'];

                                    const objList = [
                                    id: '1',
                                    name: 'aaa',
                                    ,

                                    id: '2',
                                    name: 'bbb',
                                    ,

                                    id: '3',
                                    name: 'ccc',

                                    ];

                                    const res = objList.filter(value => !idsToRemove.includes(value.id));

                                    console.log("result",res);





                                    const idsToRemove = ['3', '1'];

                                    const objList = [
                                    id: '1',
                                    name: 'aaa',
                                    ,

                                    id: '2',
                                    name: 'bbb',
                                    ,

                                    id: '3',
                                    name: 'ccc',

                                    ];

                                    const res = objList.filter(value => !idsToRemove.includes(value.id));

                                    console.log("result",res);






                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Mar 7 at 22:56









                                    dwirony

                                    4,42731334




                                    4,42731334










                                    answered Mar 7 at 10:59









                                    Khyati SharmaKhyati Sharma

                                    837




                                    837



























                                        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%2f55041973%2fremove-object-from-array-based-on-array-of-some-property-of-that-object%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

                                        Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                                        Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                                        2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived