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
。
答案 0 :(得分:4)
lodash没有比较对象的属性值;它会比较它们是否是同一个对象(内部引用)。
此代码将打印true
,因为它是同一个对象:
var ticker = { ticker: 'GOOG' }
var searchedTickers = [ticker]
var found = _.includes(searchedTickers, ticker);
console.log(found);