polonio
polonio

Reputation: 351

Ramda find function in array of nested objects

I am trying to use find function in this array

array=  [{
        type: 'banks',
        id: 25,
        attributes: { name: 'Bradescard', bankNumber: '063' },
        links: { self: '/banks/63' }
      },
      {
        type: 'banks',
        id: 26,
        attributes: { name: 'BM Goldman Sachs', bankNumber: '064' },
        links: { self: '/banks/64' }
      },
      {
        type: 'banks',
        id: 27,
        attributes: { name: 'Bracce', bankNumber: '065' },
        links: { self: '/banks/65' }
      }
    ]

if I try find(propEq('id', 27))(array) it returns the correct object, but I need to find by bankNumber.

I tried find(propEq(lensPath(['attributes', 'bankNumber']), '065'))(array) but I got undefined

How can I do this?

Upvotes: 0

Views: 206

Answers (1)

Yasser Nascimento
Yasser Nascimento

Reputation: 1381

Try to just switch propEq to pathEq.

Something like: find(pathEq(['attributes', 'bankNumber'], '065'))(array).

Upvotes: 3

Related Questions