![](/img/trans.png)
[英]If statement is true, script returns console.log() inside block but not return
[英]console.log returns value, the return statement is undefined?
因此,我正在從Google電子表格接收數據。 我需要映射它們(雇員),然后格式化我接收的日期(MomentJS),然后將該日期與存儲在另一個數組中的現有日期列表(testArr)進行比較,如果它們匹配,我需要返回員工姓名(x.name)
當我console.log()時,我得到的是正確的值,但返回時卻沒有。 返回時,我不確定,因為我正在使用.map函數,但是還有什么選擇。
這是我有史以來第一個Stackoverflow問題,因此,非常感謝您:)
let testArr = [3-2011, 5-2017, etc ...];
const finalForamting = () => {
return (employees.map(emp => {
testArr.filter(item => {
if(moment(emp.startdate).format('M-YYYY') === item) {
console.log(emp.name) --> TOM, MARK, ETC ...
return emp.name ------> undefined
}
})
)
)}
這不是filter
功能的工作原理。 請如下更新您的代碼
...
testArr.filter(item => moment(emp.startdate).format('M-YYYY') === item)
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.