【发布时间】:2019-10-08 12:48:59
【问题描述】:
所以我应该写如果项目在数组中,这个函数应该如何返回一个 cb 为真。我写了以下内容,但我在 MDN 上查看过,这是错误的。它在我看来是错误的,但我知道我应该将 return cb() 包括在等式中。我究竟做错了什么?
if(===item){
return cb(true)
} else {
return cb(false)
}
// contains checks if an item is present inside of the given array/list.
function contains(item, list, cb) {
// Pass true to the callback if it is, otherwise pass false.
我在 MDN 中收到意外的令牌错误。
【问题讨论】:
-
你可能会喜欢`includes()'
标签: javascript arrays function if-statement