0

I have the initial array of data dataToDisplay and the array that I need to add filtered arrays into it dataToDisplay. I used .filter() to do so:

this.dataToDisplay = this.dataToDisplay.filter((res)=>{
  console.log(res);
  if(res.type==this.filterArray['typeOfIns'])
  {
    this.dataToFilter = res;
    console.log(this.dataToFilter)

    //this.dataToFilter = res;
    //console.log(this.dataToFilter)
  }

})

I got an error saying:

ERROR Error: Error trying to diff '[object Object]'. Only arrays and iterables are allowed

The result at line 58: console.log(this.dataToFilter) is returning the right arrays but cannot be displayed and binded into the page.

dataToDisplay is having the following structure:

dataToDisplay = [
    {id:.., type:.., name:..},
    {id:.., type:.., name:..}
]
5
  • can you share dataToDisplay? and generally add more context as its unclear what is array and what is array of arrays? Commented Apr 25, 2019 at 20:17
  • check the edit please @SergeyRudenko Commented Apr 26, 2019 at 7:39
  • The callback of the filter method should return a boolean. It seems you do not return a boolean there. Maybe check out how filter works Commented Apr 26, 2019 at 12:11
  • cool, last bit - can you share what is filterArray object? Commented Apr 26, 2019 at 15:53
  • It worked as @Phonolog links said, just a simple return is enough, I will post an edit. Commented Apr 27, 2019 at 6:23

1 Answer 1

1

Please try below code :

this.dataToDisplay = this.dataToDisplay.filter((res)=>{
  return res.type==this.filterArray['typeOfIns']
})

This will done all the work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.