javascript - 删除数组内的多个双引号
问题描述
我有一个包含 5 个元素和 4 个双引号的数组,如何在保留其余元素的同时仅删除双引号。
let arr = ["kot"," "," ",","dart","," "];
解决方案
you can make use of String.trim
and Array.filter
arr = arr.filter(element => element.trim())
the trim
method will remove starting and trailing whitespace, so the " "
strings will be converted to ""
. Empty strings are considered falsy, so they will be removed by the filter
function.
let arr = ["ruby","javascript","golang","dart","kotlin"," "," "," "," "];
console.log(arr.filter(e => e.trim()));
推荐阅读
- python - 如何在 Python 3 中使用 Selenium 在 chrome://downloads 取消下载
- perl - 为什么我的 perl Catalyst redirect_and_detach 替换插件方法失败?
- python - 程序“python”无法运行:
- javascript - 仅当前 2 个字符相似时,React 本机搜索栏才显示平面列表
- r - 将对象的单位分配给组,而不将同一对象的单位分配给组
- javascript - 使用 jspdf 和 html2canvas 的动态 html 的多个 pdf 页面
- r - 如何在数据框中手动输入单元格?
- javascript - 以选择器为目标进行拖放
- ruby - 什么是 byebug 版本的 pry 的 whereami?
- c++ - 如何使用 CGAL 将顶点信息与基本三角剖分结合使用