我有一個返回一些數字的數組,如222.000,333.000,444.000,555.000。理想情況下,我想格式化,以便在每隔一個數字後放置一個分隔符「\ n」。即將會像Javascript在數組中每隔一個數字後添加一個休息符
222.000,333.000
444.000,555.000
可以通過修改下面的行來完成嗎?
n107 = parseFloat(output1),
n108 = parseFloat(output2),
n109 = parseFloat(output3),
n110 = parseFloat(output4),
list = [];
// add values to array if they're not NaN or > 0
if (n1) {
list.push(n1);
}
if (n2) {
list.push(n2);
}
if (n3) {
list.push(n3);
}
if (n4) {
list.push(n4);
}
if (n5) {
list.push(n5);
}
if (n6) {
list.push(n6);
}
// combine values into a string separated with commas
document.getElementById('inputTextToSave').innerHTML = list.join(",");
@Alexa這是你想要的? –
我使用上面的列表,因爲我不想打印0zeros或NaN。我會看看您的示例是否允許我不打印0zeros或NaN。 thx –