OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to filter an array of objects in React Native using multiselect?

  • Thread starter Thread starter farber
  • Start date Start date
F

farber

Guest
I am trying to filter an array of objects based on the values selected in a multiselect element in React native

If I have the following array of data:

Code:
data = [
{"_id": "01", "brand": "1", "size": "20"},
{"_id": "02", "brand": "2", "size": "21"},
{"_id": "03", "brand": "1", "size": "19"},
{"_id": "04", "brand": "3", "size": "21"},
{"_id": "05", "brand": "1", "size": "20"},
{"_id": "06", "brand": "2", "size": "20"},
{"_id": "07", "brand": "3", "size": "21"},
{"_id": "08", "brand": "3", "size": "18"},
]

then I have the following options for a multiselect dropdown, the options are selected using the useState hook and stored as an array.

Code:
const dropdownData = [
  { label: '1', value: '1' },
  { label: '2', value: '2' },
  { label: '3', value: '3' },

]

So I need to filter the data array based on the options which have been selected and stored in the dropdown array

I have tried sorting the array with standard js array filtering but I cannot seem to get it to work with the multiselect using the useState hook and filtering as options are selected.

<p>I am trying to filter an array of objects based on the values selected in a multiselect element in React native</p>
<p>If I have the following array of data:</p>
<pre><code>data = [
{"_id": "01", "brand": "1", "size": "20"},
{"_id": "02", "brand": "2", "size": "21"},
{"_id": "03", "brand": "1", "size": "19"},
{"_id": "04", "brand": "3", "size": "21"},
{"_id": "05", "brand": "1", "size": "20"},
{"_id": "06", "brand": "2", "size": "20"},
{"_id": "07", "brand": "3", "size": "21"},
{"_id": "08", "brand": "3", "size": "18"},
]
</code></pre>
<p>then I have the following options for a multiselect dropdown, the options are selected using the useState hook and stored as an array.</p>
<pre><code>const dropdownData = [
{ label: '1', value: '1' },
{ label: '2', value: '2' },
{ label: '3', value: '3' },

]

</code></pre>
<p>So I need to filter the data array based on the options which have been selected and stored in the dropdown array</p>
<p>I have tried sorting the array with standard js array filtering but I cannot seem to get it to work with the multiselect using the useState hook and filtering as options are selected.</p>
 

Latest posts

H
Replies
0
Views
1
haifisch123
H
A
Replies
0
Views
1
Adrian-Mihai Enache
A
H
Replies
0
Views
1
Hür Doğan ÜNLÜ
H
Top