过滤嵌套在一个衬垫中的另一个数组中的数组

S. *_*enk -1 javascript

我正在尝试过滤一系列嵌套数组中的空字符串条目,但 filter 实际上并没有改变数组。

const text = [
  ['222','','ghy','','hthb'],
  ['333','','ghw','','5gth'],
  ['444','','fht','','5gbh'],
]

text.map(el=>el.filter(entry => entry.trim() != ''))

console.log(text)
Run Code Online (Sandbox Code Playgroud)

Nin*_*olz 5

您可以分配映射的新数组。

var text = [['222', '', 'ghy', '', 'hthb'], ['333', '', 'ghw', '', '5gth'], ['444', '', 'fht', '', '5gbh']]

text = text.map(a => a.filter(Boolean));

console.log(text);
Run Code Online (Sandbox Code Playgroud)