javascript - Removing value from object in Angular 6 - Stack Overflow

I have some object in Angular like thisdocuments = [{name: "sto.jpg", selected: false}{name

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
Add a ment  | 

1 Answer 1

Reset to default 7

You 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

相关推荐

  • javascript - Removing value from object in Angular 6 - Stack Overflow

    I have some object in Angular like thisdocuments = [{name: "sto.jpg", selected: false}{name

    6小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信