gpt4 book ai didi

javascript - 如何在 For...of 循环中替换数组中的所有 NaN 值

转载 作者:行者123 更新时间:2023-11-30 08:17:44 24 4
gpt4 key购买 nike

如果我有以下数组

let initialdates = [2019-12-07,2019-12-08, NaN-NaN-NaN]

为什么以下内容不适用于我删除 NaN 的过程....

let initialdates = [2019 - 12 - 07, 2019 - 12 - 08, NaN - NaN - NaN]
for (let [index, dateField] of initialdates.entries()) {
if (isNaN(dateField)) {
initialdates[dateField] = "found issue";
}
}
console.log('the final array is: ' + initialdates);

它仍然打印出来......

最终数组为:2019-12-07,2019-12-02,NaN-NaN-NaN

最佳答案

initialdates[dateField] = "found issue";

应该是

initialdates[index] = "found issue";

关于javascript - 如何在 For...of 循环中替换数组中的所有 NaN 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59228308/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com