nullobject/fkit

Question: Filter array of objects based on property?

Opened this issue · 4 comments

I must be missing something...

If I have an array of objects, like:

[
  {
    a: 1,
    b: 2
  },
  {
    a: 1,
    b: 3
  },
  {
    a: 1,
    b: 2
  }
]

How can I filter it to return just the objects where b is 2? I've looked at filter, eq, and a few others. No luck. This seems like something pretty basic, so I'm sure I'm overlooking something.

Thanks.

I think this will do it:

F.filter(F.compose(F.equals(2), F.get('b')), yourList)

Geez, @CrossEye - you're everywhere answering questions. :-)

With one minor syntactical edit (F.eq instead of F.equals) this did the trick.

FWIW, my problem was that I had the filter inside the compose.

Thanks!

Thanks Scott!

NP. I like seeing what's happening in the JS FP libraries!