underscore contains (_.contains) on object types

contains requires the values to be comparable with === which will not work with different instances of objects.

For instance it would work if you passed the exact object you are searching for, which isn’t very useful.

if (_.contains(indexes, indexes[0])) {

You can however use where or findWhere.

if (_.findWhere(indexes, {'id':1, 'name': 'jake'})) {

findWhere is new in Underscore 1.4.4 so if you do not have it, you can use where.

if (_.where(indexes, {'id':1, 'name': 'jake'}).length > 0) {

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)