4 回答
TA贡献1827条经验 获得超7个赞
最后做:
arrOfChart = arrOfChart.filter(arr=>!(arr.length == 1 && arr[0] == ""))
console.log(arrOfChart)
>>>[
["Argentina", "Maroon 5:50<br>"],
["Australia", "Maroon 5:224<br>"],
["Austria", "Maroon 5:42<br>"],
["Belgium", "Maroon 5:10<br>"],
["Brazil", "Maroon 5:187<br>"],
["Canada", "Maroon 5:160<br>"],
["China", "Maroon 5:10<br>"],
["France", "Maroon 5:1533<br>"]
]
TA贡献1850条经验 获得超11个赞
要从数组中删除空值,您需要使用filter函数:
var array = [0, 1, null, 2, "", 3, undefined, 3,,,,,, 4,, 4,, 5,, 6,,,,];
var filtered = array.filter(function (el) {
return el != "";
});
console.log(filtered);
TA贡献1851条经验 获得超3个赞
你只需使用filter
let data = [["Argentina", "Maroon 5:50<br>"],
["Australia", "Maroon 5:224<br>"],
["Austria", "Maroon 5:42<br>"],
["Belgium", "Maroon 5:10<br>"],
[""],
["Brazil", "Maroon 5:187<br>"],
[""],
["Canada", "Maroon 5:160<br>"],
[""],
["China", "Maroon 5:10<br>"],
[""],
[""],
[""],
[""],
[""],
[""],
[""],
[""],
["France", "Maroon 5:1533<br>"]]
let result = data.filter(([el]) => el);
console.log(result);
TA贡献1825条经验 获得超6个赞
通过使用( to ).filter的隐式强制,您可以实现这一点""false
baseArray.filter( subArray => subArray[0]);
const baseArray = [["Argentina", "Maroon 5:50<br>"],
["Australia", "Maroon 5:224<br>"],
["Austria", "Maroon 5:42<br>"],
["Belgium", "Maroon 5:10<br>"],
[""],
["Brazil", "Maroon 5:187<br>"],
[""],
["Canada", "Maroon 5:160<br>"],
[""],
["China", "Maroon 5:10<br>"],
[""],
[""],
[""],
[""],
[""],
[""],
[""],
[""],
["France", "Maroon 5:1533<br>"]
];
const result = baseArray.filter( subArray => subArray[0]);
console.log(result);
添加回答
举报