I have some object in Angular like this
documents = [
{name: "sto.jpg", selected: false}
{name: "stosecen.jpg", selected: false}
{name: "red.png", selected: false}
{name: "maxresdefault.jpg", selected: false}
];
And some array like this
documentsForDelete = ["sto.jpg", "stosecen.jpg"];
I need to remove values from documents from documentsForDelete
This is what i have tried and no luck
remove(array, element) {
const index = array.indexOf(element);
array.splice(index, 1);
}
remove(documents.name, documentsForDelete);
I have some object in Angular like this
documents = [
{name: "sto.jpg", selected: false}
{name: "stosecen.jpg", selected: false}
{name: "red.png", selected: false}
{name: "maxresdefault.jpg", selected: false}
];
And some array like this
documentsForDelete = ["sto.jpg", "stosecen.jpg"];
I need to remove values from documents from documentsForDelete
This is what i have tried and no luck
remove(array, element) {
const index = array.indexOf(element);
array.splice(index, 1);
}
remove(documents.name, documentsForDelete);
Share
edited Dec 5, 2018 at 7:12
Miomir Dancevic
asked Dec 5, 2018 at 7:09
Miomir DancevicMiomir Dancevic
6,85216 gold badges85 silver badges154 bronze badges
2
- 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 reproducible example. For more information, please see How to Ask and take the tour. – CertainPerformance Commented Dec 5, 2018 at 7:10
- I have tried and added my solution – Miomir Dancevic Commented Dec 5, 2018 at 7:12
1 Answer
Reset to default 7You can get the resultant array using .filter()
:
let data = [
{name: "sto.jpg", selected: false},
{name: "stosecen.jpg", selected: false},
{name: "red.png", selected: false},
{name: "maxresdefault.jpg", selected: false}
];
let array = ["sto.jpg", "stosecen.jpg"];
let result = data.filter(({ name }) => !array.includes(name));
console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745058054a4608791.html
评论列表(0条)