I would like to filter an array of objects if one of the keys contains so string. given the data:
const data = [
{id: 1, value: 'abs', x: 'ee'}
{id: 2, value: 'ws', x: '21'},
{id: 3, value: 'asd', x: 'as'},
{id: 4, value: 'x', x: 'ee'},
]
I want to be able given the sting or number to filter this array if some value contains the given input if i get w
i want to be able to get only the second element if i get a
i want to be able to get the first and third element and so on.
thanks ahead
You can do it like this:
const data = [
{id: 1, value: 'abs', x: 'ee'},
{id: 2, value: 'ws', x: '21'},
{id: 3, value: 'asd', x: 'as'},
{id: 4, value: 'x', x: 'ee'}
]
const customFilter = val => R.filter(R.compose(R.any(R.contains(val)),R.values))
console.log(customFilter('a')(data))
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.25.0/ramda.min.js"></script>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments