在数组的数组中搜索,return 结果是一个数组

search in array of array, and return results in one array

使用下面的数组数组,我需要按字母搜索,如果找到该元素,它应该 return 在一个数组中

例子

const data= [[
      "car",
      "plane",
      "boat"
  ],
  [
      "cartago",
      "barcelona",
      "los angeles"
  ],
  [
      "headphone",
      "phone",
      "camera",
  ]
]

如果匹配“ca”必须return

[car, cartago, camera]

如果匹配“ne”必须return

[plane, headphone, phone]

展开数组并通过检查子字符串是否包含在每个元素中来过滤它

const data= [[      "car",      "plane",      "boat"  ],  [      "cartago",      "barcelona",      "los angeles"  ],  [      "headphone",      "phone",      "camera",  ]]

let a = data.flat().filter(v => v.includes('ca'))
console.log(a)

let b = data.flat().filter(v => v.includes('ne'))
console.log(b)