Quantcast
Channel: Ionic Forum - Latest posts
Viewing all articles
Browse latest Browse all 228595

How to nicely filter inside an array of object?

$
0
0

You can actually shorten the code with a bit of logic:

return this.items.filter((item) => {
  if (item.id.indexOf(str) >= 0 ||
      item.name.indexOf(str) >= 0 ||
      item.position.indexOf(str) >= 0) {
    return true
  }
  return false
})

Now it's 8 lines instead of 12, well actually 6 if you think the if condition as 1 long line.


Viewing all articles
Browse latest Browse all 228595

Trending Articles