Delete particular objects from array in javascript
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
|
show 1 more comment
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
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
|
show 1 more comment
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
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
javascript arrays
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
|
show 1 more comment
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
|
show 1 more comment
4 Answers
4
active
oldest
votes
You can try using the javascript array.filter
todos=todos.filter(todo=>!todo.completed);
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
add a comment |
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}];
add a comment |
Something like this would do the job
var filteredAry = todos.filter(function(e) { return e.competed !== 'true' })
1
This won't work because, firstly,"completed"is misspelled. But, secondly, you've put quotes aroundtrue.
– CJK
Nov 24 '18 at 10:42
add a comment |
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
You can try using the javascript array.filter
todos=todos.filter(todo=>!todo.completed);
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
add a comment |
You can try using the javascript array.filter
todos=todos.filter(todo=>!todo.completed);
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
add a comment |
You can try using the javascript array.filter
todos=todos.filter(todo=>!todo.completed);
You can try using the javascript array.filter
todos=todos.filter(todo=>!todo.completed);
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
add a comment |
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
add a comment |
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}];
add a comment |
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}];
add a comment |
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}];
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}];
answered Nov 24 '18 at 11:21
Anand SAnand S
45718
45718
add a comment |
add a comment |
Something like this would do the job
var filteredAry = todos.filter(function(e) { return e.competed !== 'true' })
1
This won't work because, firstly,"completed"is misspelled. But, secondly, you've put quotes aroundtrue.
– CJK
Nov 24 '18 at 10:42
add a comment |
Something like this would do the job
var filteredAry = todos.filter(function(e) { return e.competed !== 'true' })
1
This won't work because, firstly,"completed"is misspelled. But, secondly, you've put quotes aroundtrue.
– CJK
Nov 24 '18 at 10:42
add a comment |
Something like this would do the job
var filteredAry = todos.filter(function(e) { return e.competed !== 'true' })
Something like this would do the job
var filteredAry = todos.filter(function(e) { return e.competed !== 'true' })
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 aroundtrue.
– CJK
Nov 24 '18 at 10:42
add a comment |
1
This won't work because, firstly,"completed"is misspelled. But, secondly, you've put quotes aroundtrue.
– 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
add a comment |
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
add a comment |
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
add a comment |
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
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
answered Nov 24 '18 at 10:40
Burak GüneliBurak Güneli
368
368
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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