Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to filter on array of array in react?

I have below array of arrays in my React application which I need to filter based on first column.

First column contains list of companies.

const rowData = [
  ['Capri LLC', '0012345', 'A0012', 'Y', 'View Details'],
  ['Capricorn INC', '0022345', 'B0012', 'N', 'View Details'],
  ['Cancer INC', '0033345', 'A0012', 'Y', 'View Details'],
  ['Gemini LLC', '0052345', 'C0012', 'Y', 'View Details'],
  ['Leo Land INC', '0052345', 'D0012', 'Y', 'View Details'],
  ['Capri LLC', '0012345', 'A0012', 'Y', 'View Details'],
  ['Capricorn INC', '0022345', 'B0012', 'N', 'View Details'],
  ['Cancer INC', '0033345', 'A0012', 'Y', 'View Details'],
  ['Gemini LLC', '0052345', 'C0012', 'Y', 'View Details'],
  ['Leo Land INC', '0052345', 'D0012', 'Y', 'View Details'],
];

So if I search for Capri, it should the final output should be,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

const rowData = [
      ['Capri LLC', '0012345', 'A0012', 'Y', 'View Details'],
      ['Capricorn INC', '0022345', 'B0012', 'N', 'View Details'],
      ['Capri LLC', '0012345', 'A0012', 'Y', 'View Details'],
      ['Capricorn INC', '0022345', 'B0012', 'N', 'View Details'],
];

I tried applying the .filter() method we use for one dimensional array however while applying that for array of arrays, I am doing some syntax mistake.

>Solution :

Try:

rowData.filter(a => a[0].includes('Capri'));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading