如何基于数组检查+ if语句返回值?

时间:2019-05-02 12:40:08

标签: function return arrow-functions

我收到有关以下功能的警告

function currencySubmenuTitle(ctx) {
    let id = Object.keys(currencies).find(element => {
        if (currencies[element].id === ctx.match[1]) {
             return element
        }
    })
    if (typeof id === 'undefined' || id === null) {
        return "No match found"
    } else {
        return ` ${toTitleCase(id)} : ${currencies[id].current}`
    }
}

注意:我的ID和元素是不同的,所以我不能只接受元素并将其用作字符串返回。

警告是:

2:51  warning  Expected to return a value at the end of arrow function  array-callback-return
2:51  warning  Expected to return a value at the end of arrow function  consistent-return

如何以兼容的方式在此函数中返回我的值(即不是我的操作方式) 我能证明这个吗?根据数组求值的返回运行if语句?

1 个答案:

答案 0 :(得分:0)

语句的评估可以在返回行中进行,因此此处不需要特定的if语句。只需:

SELECT * employees;
相关问题