Ramda how to filter array of objects where some key contains

tubu13

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

Håken Lid

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.

edited at
0

Comments

0 comments
Login to comment

Related

How to filter an array of objects when object key contains specific values

How to sort an array of objects based on nested key using Ramda?

Filter an object containing a key that contains an array of objects using an array of strings

Ramda, check(filter) if array of strings contains substring

Postgres how to find rows where in jsonb type column contains key with array which contain some value with or condition

How to filter an array of objects, based on some fields?

JavaScript How to filter array of objects by dynamic key?

How to transform array of arrays into an array of objects with Ramda?

jq How to filter array object does not contains Key with case insensitively?

JavaScript: How to filter a JSON array if the key contains special characters?

How type JSON schema where array contains objects?

Mongodb : How to select objects where an array contains only a specific field?

How to make array of objects that contains key-values in golang?

Filter an array of objects and return an array of objects where the value of a key appears x times

How to use array .filter() to search key value in JSON array of objects

Ramda: How to filter based on a value in a nested array

How to filter records in a nested array using ramda?

Filter Array of objects by specific key

Ramda - combine duplicates of objects in array with same key value

How to filter objects in array by category key in Angular ng-repeat

How to filter array of objects from key value pair in properties

How to use filter to search in multiple key values of objects in an array?

How to filter an array of objects by the object's key in Javascript

Filter an array of objects according to the name of the key in the objects

SwiftUI - Filter using .contains for a nested array of objects

how to filter array where a key's value matches in php

How to check if an array of objects where I push into objects has a specific key value from another array of objects

How to filter array of objects by another array of objects and add key/value to the result array?

How to represent in typescript a list of objects where the key is the date and the content is an array?