skip to Main Content
 {
    "id":805,
    "name":'test',
    "Email":[
    {
    "Name":"name1",
    "Email":"[email protected]"
    },
    {
    "Name":"name2",
    "Email":"[email protected]"
    }
    ..
    ..
    ],
    "createdDate":"..."
    },
    {
    "id":806,
    "name":'test',
    "Email":[
    {
    "Name":"name1",
    "Email":"[email protected]"
    },
    {
    "Name":"name2",
    "Email":"[email protected]"
    }
    ..
    ..
    ],
    "createdDate":"..."
    }





 this.data=this.data.filter((item=> this.selectedId.includes(item.id)));

where this.selectedId = [‘805′,’806’]

let email='[email protected]';

if Email contains this [email protected] then that data also we need to show.

 this.data=this.data.filter((item=> this.selectedId.includes(item.id)) || Object.keys(item.Email).includes(email));

2

Answers


  1. function getKeyByValue(object, value) {
      return Object.keys(object).find(key => object[key] === value);
    }
    
    
    const map = {"first" : "1", "second" : "2"};
    console.log(getKeyByValue(map,"2"));
    Login or Signup to reply.
  2. Your syntax is incorrect for the lambda expression/function.

    While you can use the .find() with double negation (!!) to indicate the Email filter returns value.

    this.data = this.data.filter(item => this.selectedId.includes(item.id)
        || !!item.Email.find(x => x.Email == this.email));
    

    Or with .findIndex()

    this.data = this.data.filter(item => this.selectedId.includes(item.id)
        || item.Email.findIndex(x => x.Email == this.email) > -1);
    

    Note that with selectedId = ['805','806'], you will get the incompatible error as the ids provided in your data array are Number.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search