我尝试在parseInt(string,10)之后编写> = 20,但这不起作用。所以在我将数组项转换为整数后,我是否检查它们是否大于20?
const strings = ["10", "20","40","","50", "60", "70"];
const numbers = strings.map(string => parseInt(string,10));
console.log(numbers);
答案 0 :(得分:0)
您可以将Array#filter
与条件一起使用,并映射获取数字数组的值。
var strings = ["10", "20","40","","50", "60", "70"],
numbers = strings
.filter(v => +v >= 20)
.map(Number);
console.log(numbers);