Find an object by id in array Ramda

Arthur

For example I have something like:

const stuff = {
  "31": [
    {
      "id": "11",
      "title": "ramda heeeelp"
    },
    {
      "id": "12",
      "title": "ramda 123"
    }
  ],
  "33": [
    {
      "id": "3",
      "title": "..."
    }
  ],
  "4321": [
    {
      "id": "1",
      "title": "hello world"
    }
  ]
}

I need to find object with id 11. How I did:

map(key => find(propEq('id', 11))(stuff[key]), keys(stuff)) 

However it returns [{..object with id 11..}, undefined, undefined] due to map. Ok, we could check if object isn't undefined, but it isn't clear as I want.

Ori Drori

Get the values of the object, flatten the array of arrays, and use find and propEq to get the object:

const { pipe, values, flatten, find, propEq } = R

const findById = id => pipe(
  values,
  flatten,
  find(propEq({ id }))
)

const data = {"31":[{"id":"11","title":"ramda heeeelp"},{"id":"12","title":"ramda 123"}],"33":[{"id":"3","title":"..."}],"4321":[{"id":"1","title":"hello world"}]}

const result = findById('11')(data)

console.log(result)
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.26.1/ramda.js"></script>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Delete object by id from array Ramda

From Dev

Find object with given id in nested arrays with ramda, get all properties except children array

From Dev

How to use Ramda to find matching object in Array by key value

From Dev

Ramda, find value in sub array

From Dev

Insert a new object to array Ramda

From Dev

change an object property in array with ramda

From Dev

Ramda sort array of nested object

From Javascript

Ramda - Convert array of objects into object

From Dev

find object in array, to find object where id match substring

From Dev

find object by id which is in array mongoose

From Javascript

Find object by id in an array of JavaScript objects

From Dev

Find index of object by id in array of arrays

From Dev

mongoose query: find an object by id in an array

From Dev

Find and replace object in array (based on id)

From Dev

How to find object by id in array of objects?

From Dev

Better find object with ID in array of NSManagedObject

From Javascript

Ramda: convert key value array to object

From Dev

Pointfree Join Array to String, by key in object, in Ramda

From Dev

How to transform object map to array with Ramda?

From Dev

Is value in array or string inside object Ramda

From Dev

Convert array of arrays to object of arrays, using ramda

From Dev

Ramda - Pick from an object and return an array

From Dev

Ramda: Duplicate an object by its (array) property

From Dev

Ramda: Find lowest occasions of one array in another array

From Dev

Move object from array A to array B. Ramda.js

From Dev

How to use _.where to find by ID an object nested in an array of objects?

From Dev

How to find object with id value in deep nested array?

From Dev

find subdocument by id inside a array field of nested object

From Dev

find largest id within array object using $.each

Related Related

  1. 1

    Delete object by id from array Ramda

  2. 2

    Find object with given id in nested arrays with ramda, get all properties except children array

  3. 3

    How to use Ramda to find matching object in Array by key value

  4. 4

    Ramda, find value in sub array

  5. 5

    Insert a new object to array Ramda

  6. 6

    change an object property in array with ramda

  7. 7

    Ramda sort array of nested object

  8. 8

    Ramda - Convert array of objects into object

  9. 9

    find object in array, to find object where id match substring

  10. 10

    find object by id which is in array mongoose

  11. 11

    Find object by id in an array of JavaScript objects

  12. 12

    Find index of object by id in array of arrays

  13. 13

    mongoose query: find an object by id in an array

  14. 14

    Find and replace object in array (based on id)

  15. 15

    How to find object by id in array of objects?

  16. 16

    Better find object with ID in array of NSManagedObject

  17. 17

    Ramda: convert key value array to object

  18. 18

    Pointfree Join Array to String, by key in object, in Ramda

  19. 19

    How to transform object map to array with Ramda?

  20. 20

    Is value in array or string inside object Ramda

  21. 21

    Convert array of arrays to object of arrays, using ramda

  22. 22

    Ramda - Pick from an object and return an array

  23. 23

    Ramda: Duplicate an object by its (array) property

  24. 24

    Ramda: Find lowest occasions of one array in another array

  25. 25

    Move object from array A to array B. Ramda.js

  26. 26

    How to use _.where to find by ID an object nested in an array of objects?

  27. 27

    How to find object with id value in deep nested array?

  28. 28

    find subdocument by id inside a array field of nested object

  29. 29

    find largest id within array object using $.each

HotTag

Archive