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.
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.
Comments