我有这个:
values.map(value => {
if (value.gse === gse) {
return value.y
}
})
仅在示例中放入 if
语句的情况下,我才需要映射然后返回 value.y
。
如何避免 Expected to return a value at the end of arrow function
的警告,我的意思是,我应该如何正确编写该代码?如果 value.gse !== gse
?
return this
最佳答案
您需要使用filter
,然后使用map
:
values.filter(value => values.gse === gse).map(value => value.y);
关于JavaScript,期望在箭头函数末尾返回一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57560407/