我正在尝试过滤一系列嵌套数组中的空字符串条目,但 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)
您可以分配映射的新数组。
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)
| 归档时间: |
|
| 查看次数: |
56 次 |
| 最近记录: |