【问题标题】:Why is this logging as undefined?为什么此日志记录未定义?
【发布时间】:2017-08-03 19:56:01
【问题描述】:

我正在使用 jQuery 和 Lodash,但不知道为什么返回 undefined:

$.each(someArray, function(i) {
  var x = _.find(someObject, function(item) {
    return item.Id === someArray[i]
  });
  console.log('x')
  console.log(x)
});

【问题讨论】:

  • 什么是someObject,什么是someArray?鉴于let someArray = [2], someObject = [{Id: 2, Label: 'String'}];,我没有得到未定义。

标签: javascript jquery find lodash


【解决方案1】:

来自文档:

返回匹配的元素,否则未定义。

意味着你没有匹配。

https://lodash.com/docs/4.17.4#find

现在你需要找出原因。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    • 2016-08-02
    • 2020-08-16
    • 2016-04-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多