这里我有一些本地函数,它应该将一些包含一些值的 HTML 标签(键)转换为数组。某些产品的每个结束标签都有 2x '\n' 包含在数组中。
如何从数组中删除断线?
function cleanCatalog(s){
const separateValues = /<\/?[^>]+(>|$)/g;
let newLocal = s.replace(separateValues, " ");
let cleanText = newLocal;
let catalogArray = [cleanText.split(" ")];
return catalogArray;
}
输出:
"["drill", "99", "5", "↵↵", "hammer", "10", "50", "↵↵", ...]"
最佳答案
尝试通过排除 new lines 来过滤数组.
const outputWithoutNewLines = output.filter(el => el !== '\n');
关于javascript - 如何从数组 [JS] 中删除换行字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54853724/