To filter an array of objects based on a key value, you can use the Array.filter()
method along with a callback function that checks each object's key value. Here's an example:
index.tsx217 chars11 lines
In this example, we have an array of objects data
with each object having an id
and a name
key. We want to filter all the objects where the name
is equal to 'Jane'
. We pass a callback function to the Array.filter()
method that checks if the name
key matches our filter value ('Jane'
). The filter()
method returns a new array (filteredData
) with all objects that pass our filter.
gistlibby LogSnag