forEach返回未定义 [英] forEach returns undefined
本文介绍了forEach返回未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用moment.js并尝试使用该代码处理日期
I'm using moment.js and trying to process a date using that code
function toISOdate (date) {
return moment(date, 'DD.MM.YYYY').toISOString()
}
function toMomentDate (date) {
return moment(date)
}
let input = "25.11.2017-25.11.2017"
let dateArray = input
.split('-')
.forEach(toISOdate)
console.log(dateArray, input)
但是问题是dateArray返回未定义.也许这是一个非常明显的错误,但我找不到它.
But the problem is that dateArray returns undefined. Maybe it's very obvious mistake, but I can't find it.
推荐答案
使用
一个新数组,每个元素都是回调函数的结果.
A new array with each element being the result of the callback function. 代替 这篇关于forEach返回未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
forEach()
. forEach
不不返回任何内容(undefined
).
查看全文