如何在React中筛选嵌套数组?
P粉022501495
2023-08-15 14:31:04
<p>我在我的React应用程序中有一个数组的数组,我需要根据第一列进行过滤。</p>
<p>第一列包含公司列表。</p>
<pre class="brush:php;toolbar:false;">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'],
];</pre>
<p>所以如果我搜索Capri,最终输出应该是:</p>
<pre class="brush:php;toolbar:false;">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'],
];</pre>
<p>我尝试应用我们用于一维数组的.filter()方法,但是在应用于数组的数组时,我犯了一些语法错误。</p>
试一下这个: