Delete particular objects from array in javascript












0















I have a object of array stored in local-storage as shown below



  var todos = [
{"id":0,"text":"Make lunch","completed":true},
{"id":1,"text":"Do laundry","completed":false},
{"id":2,"text":"Complete Project","completed":true}
]


How can i delete all objects that are completed?
Please tell me how to delete it with splice method as i cant replace array i want to just remove it from array!(as my project requirements)
Thanks for any help










share|improve this question




















  • 1





    The posted question does not appear to include any attempt at all to solve the problem. StackOverflow expects you to try to solve your own problem first, as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific roadblock you're running into a Minimal, Complete, and Verifiable example. For more information, please see How to Ask and take the tour.

    – CertainPerformance
    Nov 24 '18 at 10:35











  • I tried todos.splice(todos.findIndex((todo) => todo.completed), 1); but it wont worked.

    – Darshit
    Nov 24 '18 at 10:37











  • @Darshit use this Underscore library filter function underscorejs.org/#filter

    – Pranesh Janarthanan
    Nov 24 '18 at 10:47













  • Please tell me how to delete it with splice method as i cant replace array i want to just remove it from array!

    – Darshit
    Nov 24 '18 at 11:05











  • That is unfair - you asked a question, which @Fawzi answered correctly, and you accepted. Then you changed the question, and unselected Fawzi's answer. That is disrespectful of people's efforts that they've put into helping you, and it will make people far less inclined to help you now or in the future.

    – CJK
    Nov 24 '18 at 11:08


















0















I have a object of array stored in local-storage as shown below



  var todos = [
{"id":0,"text":"Make lunch","completed":true},
{"id":1,"text":"Do laundry","completed":false},
{"id":2,"text":"Complete Project","completed":true}
]


How can i delete all objects that are completed?
Please tell me how to delete it with splice method as i cant replace array i want to just remove it from array!(as my project requirements)
Thanks for any help










share|improve this question




















  • 1





    The posted question does not appear to include any attempt at all to solve the problem. StackOverflow expects you to try to solve your own problem first, as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific roadblock you're running into a Minimal, Complete, and Verifiable example. For more information, please see How to Ask and take the tour.

    – CertainPerformance
    Nov 24 '18 at 10:35











  • I tried todos.splice(todos.findIndex((todo) => todo.completed), 1); but it wont worked.

    – Darshit
    Nov 24 '18 at 10:37











  • @Darshit use this Underscore library filter function underscorejs.org/#filter

    – Pranesh Janarthanan
    Nov 24 '18 at 10:47













  • Please tell me how to delete it with splice method as i cant replace array i want to just remove it from array!

    – Darshit
    Nov 24 '18 at 11:05











  • That is unfair - you asked a question, which @Fawzi answered correctly, and you accepted. Then you changed the question, and unselected Fawzi's answer. That is disrespectful of people's efforts that they've put into helping you, and it will make people far less inclined to help you now or in the future.

    – CJK
    Nov 24 '18 at 11:08
















0












0








0








I have a object of array stored in local-storage as shown below



  var todos = [
{"id":0,"text":"Make lunch","completed":true},
{"id":1,"text":"Do laundry","completed":false},
{"id":2,"text":"Complete Project","completed":true}
]


How can i delete all objects that are completed?
Please tell me how to delete it with splice method as i cant replace array i want to just remove it from array!(as my project requirements)
Thanks for any help










share|improve this question
















I have a object of array stored in local-storage as shown below



  var todos = [
{"id":0,"text":"Make lunch","completed":true},
{"id":1,"text":"Do laundry","completed":false},
{"id":2,"text":"Complete Project","completed":true}
]


How can i delete all objects that are completed?
Please tell me how to delete it with splice method as i cant replace array i want to just remove it from array!(as my project requirements)
Thanks for any help







javascript arrays






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 11:06







Darshit

















asked Nov 24 '18 at 10:34









DarshitDarshit

3017




3017








  • 1





    The posted question does not appear to include any attempt at all to solve the problem. StackOverflow expects you to try to solve your own problem first, as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific roadblock you're running into a Minimal, Complete, and Verifiable example. For more information, please see How to Ask and take the tour.

    – CertainPerformance
    Nov 24 '18 at 10:35











  • I tried todos.splice(todos.findIndex((todo) => todo.completed), 1); but it wont worked.

    – Darshit
    Nov 24 '18 at 10:37











  • @Darshit use this Underscore library filter function underscorejs.org/#filter

    – Pranesh Janarthanan
    Nov 24 '18 at 10:47













  • Please tell me how to delete it with splice method as i cant replace array i want to just remove it from array!

    – Darshit
    Nov 24 '18 at 11:05











  • That is unfair - you asked a question, which @Fawzi answered correctly, and you accepted. Then you changed the question, and unselected Fawzi's answer. That is disrespectful of people's efforts that they've put into helping you, and it will make people far less inclined to help you now or in the future.

    – CJK
    Nov 24 '18 at 11:08
















  • 1





    The posted question does not appear to include any attempt at all to solve the problem. StackOverflow expects you to try to solve your own problem first, as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific roadblock you're running into a Minimal, Complete, and Verifiable example. For more information, please see How to Ask and take the tour.

    – CertainPerformance
    Nov 24 '18 at 10:35











  • I tried todos.splice(todos.findIndex((todo) => todo.completed), 1); but it wont worked.

    – Darshit
    Nov 24 '18 at 10:37











  • @Darshit use this Underscore library filter function underscorejs.org/#filter

    – Pranesh Janarthanan
    Nov 24 '18 at 10:47













  • Please tell me how to delete it with splice method as i cant replace array i want to just remove it from array!

    – Darshit
    Nov 24 '18 at 11:05











  • That is unfair - you asked a question, which @Fawzi answered correctly, and you accepted. Then you changed the question, and unselected Fawzi's answer. That is disrespectful of people's efforts that they've put into helping you, and it will make people far less inclined to help you now or in the future.

    – CJK
    Nov 24 '18 at 11:08










1




1





The posted question does not appear to include any attempt at all to solve the problem. StackOverflow expects you to try to solve your own problem first, as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific roadblock you're running into a Minimal, Complete, and Verifiable example. For more information, please see How to Ask and take the tour.

– CertainPerformance
Nov 24 '18 at 10:35





The posted question does not appear to include any attempt at all to solve the problem. StackOverflow expects you to try to solve your own problem first, as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific roadblock you're running into a Minimal, Complete, and Verifiable example. For more information, please see How to Ask and take the tour.

– CertainPerformance
Nov 24 '18 at 10:35













I tried todos.splice(todos.findIndex((todo) => todo.completed), 1); but it wont worked.

– Darshit
Nov 24 '18 at 10:37





I tried todos.splice(todos.findIndex((todo) => todo.completed), 1); but it wont worked.

– Darshit
Nov 24 '18 at 10:37













@Darshit use this Underscore library filter function underscorejs.org/#filter

– Pranesh Janarthanan
Nov 24 '18 at 10:47







@Darshit use this Underscore library filter function underscorejs.org/#filter

– Pranesh Janarthanan
Nov 24 '18 at 10:47















Please tell me how to delete it with splice method as i cant replace array i want to just remove it from array!

– Darshit
Nov 24 '18 at 11:05





Please tell me how to delete it with splice method as i cant replace array i want to just remove it from array!

– Darshit
Nov 24 '18 at 11:05













That is unfair - you asked a question, which @Fawzi answered correctly, and you accepted. Then you changed the question, and unselected Fawzi's answer. That is disrespectful of people's efforts that they've put into helping you, and it will make people far less inclined to help you now or in the future.

– CJK
Nov 24 '18 at 11:08







That is unfair - you asked a question, which @Fawzi answered correctly, and you accepted. Then you changed the question, and unselected Fawzi's answer. That is disrespectful of people's efforts that they've put into helping you, and it will make people far less inclined to help you now or in the future.

– CJK
Nov 24 '18 at 11:08














4 Answers
4






active

oldest

votes


















3














You can try using the javascript array.filter



todos=todos.filter(todo=>!todo.completed);





share|improve this answer
























  • never used angular before, but check this out as you might be calling the updated outside Angular zone.

    – Fawzi
    Nov 24 '18 at 11:06



















2














var todos = [
{"id":0,"text":"Make lunch","completed":true},
{"id":1,"text":"Do laundry","completed":false},
{"id":2,"text":"Complete Project","completed":true} ];

var inCompletes = todos.filter(item => !item.completed );


inCompletes will return an array of objects with completed is false.



Output



inCompletes = [{"id":1,"text":"Do laundry","completed":false}];





share|improve this answer































    0














    Something like this would do the job



    var filteredAry = todos.filter(function(e) { return e.competed !== 'true' })





    share|improve this answer



















    • 1





      This won't work because, firstly, "completed" is misspelled. But, secondly, you've put quotes around true.

      – CJK
      Nov 24 '18 at 10:42



















    0














    You can filter uncompleted todos like:



    const unCompletedTodos = todos.filter(todo => !todo.completed);


    Also you don't have to use const you can use var but I recommend you to use const or let instead of var






    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%2f53457261%2fdelete-particular-objects-from-array-in-javascript%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









      3














      You can try using the javascript array.filter



      todos=todos.filter(todo=>!todo.completed);





      share|improve this answer
























      • never used angular before, but check this out as you might be calling the updated outside Angular zone.

        – Fawzi
        Nov 24 '18 at 11:06
















      3














      You can try using the javascript array.filter



      todos=todos.filter(todo=>!todo.completed);





      share|improve this answer
























      • never used angular before, but check this out as you might be calling the updated outside Angular zone.

        – Fawzi
        Nov 24 '18 at 11:06














      3












      3








      3







      You can try using the javascript array.filter



      todos=todos.filter(todo=>!todo.completed);





      share|improve this answer













      You can try using the javascript array.filter



      todos=todos.filter(todo=>!todo.completed);






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 24 '18 at 10:38









      FawziFawzi

      267110




      267110













      • never used angular before, but check this out as you might be calling the updated outside Angular zone.

        – Fawzi
        Nov 24 '18 at 11:06



















      • never used angular before, but check this out as you might be calling the updated outside Angular zone.

        – Fawzi
        Nov 24 '18 at 11:06

















      never used angular before, but check this out as you might be calling the updated outside Angular zone.

      – Fawzi
      Nov 24 '18 at 11:06





      never used angular before, but check this out as you might be calling the updated outside Angular zone.

      – Fawzi
      Nov 24 '18 at 11:06













      2














      var todos = [
      {"id":0,"text":"Make lunch","completed":true},
      {"id":1,"text":"Do laundry","completed":false},
      {"id":2,"text":"Complete Project","completed":true} ];

      var inCompletes = todos.filter(item => !item.completed );


      inCompletes will return an array of objects with completed is false.



      Output



      inCompletes = [{"id":1,"text":"Do laundry","completed":false}];





      share|improve this answer




























        2














        var todos = [
        {"id":0,"text":"Make lunch","completed":true},
        {"id":1,"text":"Do laundry","completed":false},
        {"id":2,"text":"Complete Project","completed":true} ];

        var inCompletes = todos.filter(item => !item.completed );


        inCompletes will return an array of objects with completed is false.



        Output



        inCompletes = [{"id":1,"text":"Do laundry","completed":false}];





        share|improve this answer


























          2












          2








          2







          var todos = [
          {"id":0,"text":"Make lunch","completed":true},
          {"id":1,"text":"Do laundry","completed":false},
          {"id":2,"text":"Complete Project","completed":true} ];

          var inCompletes = todos.filter(item => !item.completed );


          inCompletes will return an array of objects with completed is false.



          Output



          inCompletes = [{"id":1,"text":"Do laundry","completed":false}];





          share|improve this answer













          var todos = [
          {"id":0,"text":"Make lunch","completed":true},
          {"id":1,"text":"Do laundry","completed":false},
          {"id":2,"text":"Complete Project","completed":true} ];

          var inCompletes = todos.filter(item => !item.completed );


          inCompletes will return an array of objects with completed is false.



          Output



          inCompletes = [{"id":1,"text":"Do laundry","completed":false}];






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 24 '18 at 11:21









          Anand SAnand S

          45718




          45718























              0














              Something like this would do the job



              var filteredAry = todos.filter(function(e) { return e.competed !== 'true' })





              share|improve this answer



















              • 1





                This won't work because, firstly, "completed" is misspelled. But, secondly, you've put quotes around true.

                – CJK
                Nov 24 '18 at 10:42
















              0














              Something like this would do the job



              var filteredAry = todos.filter(function(e) { return e.competed !== 'true' })





              share|improve this answer



















              • 1





                This won't work because, firstly, "completed" is misspelled. But, secondly, you've put quotes around true.

                – CJK
                Nov 24 '18 at 10:42














              0












              0








              0







              Something like this would do the job



              var filteredAry = todos.filter(function(e) { return e.competed !== 'true' })





              share|improve this answer













              Something like this would do the job



              var filteredAry = todos.filter(function(e) { return e.competed !== 'true' })






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 24 '18 at 10:37









              thepolishboythepolishboy

              246




              246








              • 1





                This won't work because, firstly, "completed" is misspelled. But, secondly, you've put quotes around true.

                – CJK
                Nov 24 '18 at 10:42














              • 1





                This won't work because, firstly, "completed" is misspelled. But, secondly, you've put quotes around true.

                – CJK
                Nov 24 '18 at 10:42








              1




              1





              This won't work because, firstly, "completed" is misspelled. But, secondly, you've put quotes around true.

              – CJK
              Nov 24 '18 at 10:42





              This won't work because, firstly, "completed" is misspelled. But, secondly, you've put quotes around true.

              – CJK
              Nov 24 '18 at 10:42











              0














              You can filter uncompleted todos like:



              const unCompletedTodos = todos.filter(todo => !todo.completed);


              Also you don't have to use const you can use var but I recommend you to use const or let instead of var






              share|improve this answer




























                0














                You can filter uncompleted todos like:



                const unCompletedTodos = todos.filter(todo => !todo.completed);


                Also you don't have to use const you can use var but I recommend you to use const or let instead of var






                share|improve this answer


























                  0












                  0








                  0







                  You can filter uncompleted todos like:



                  const unCompletedTodos = todos.filter(todo => !todo.completed);


                  Also you don't have to use const you can use var but I recommend you to use const or let instead of var






                  share|improve this answer













                  You can filter uncompleted todos like:



                  const unCompletedTodos = todos.filter(todo => !todo.completed);


                  Also you don't have to use const you can use var but I recommend you to use const or let instead of var







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 24 '18 at 10:40









                  Burak GüneliBurak Güneli

                  368




                  368






























                      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%2f53457261%2fdelete-particular-objects-from-array-in-javascript%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

                      Futebolista

                      Feedback on college project

                      Albești (Vaslui)