为什么lodash _.include没有发现我的Array包含它正在检查的对象?

时间:2016-06-21 19:29:23

标签: javascript lodash

https://jsfiddle.net/leongaban/yLv6t5am/

LoDash _.includes

var searchedTickers = [
    {
        ticker: 'GOOG'
    }
]

var ticker = { ticker: 'GOOG' }

var found = _.includes(searchedTickers, ticker);

console.log(found);

^它目前告诉我found = false。它应该是true

1 个答案:

答案 0 :(得分:4)

lodash没有比较对象的属性值;它会比较它们是否是同一个对象(内部引用)。

此代码将打印true,因为它是同一个对象:

var ticker = { ticker: 'GOOG' }

var searchedTickers = [ticker]

var found = _.includes(searchedTickers, ticker);

console.log(found);