如何在JavaScript中将十进制字符串数组转换为不带十进制的整数字符串数组
我们需要编写一个包含十进制字符串数组的JavaScript函数。该函数应返回一个整数字符串数组,该整数字符串是通过对数组的原始对应十进制值求和而获得的。
例如,如果输入数组为-
const input = ["1.00","-2.5","5.33333","8.984563"];
那么输出应该是-
const output = ["1","-2","5","8"];
示例
为此的代码将是-
const input = ["1.00","-2.5","5.33333","8.984563"];
const roundIntegers = arr => {
const res = [];
arr.forEach((el, ind) => {
const strNum = String(el);
res[ind] = parseInt(strNum);
});
return res;
};
console.log(roundIntegers(input));输出结果
控制台中的输出-
[ 1, -2, 5, 8 ]
热门推荐
4 短祝福语简短暖心
6 怎么说祝福语简短
10 周末祝福语正能量简短
11 周末思念祝福语大全简短
12 团队文案祝福语简短励志
13 简短的出行工作祝福语
14 高考前祝福语简短字句
15 最搞笑生日祝福语简短
16 对生活祝福语简短精辟
17 新婚贺词简短的祝福语
18 好听的元旦简短祝福语