1
let array = [1234, 1233, 1232];

console.log(_.some(array, 1234));

It returns false. Do you know why?

Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188
Xavier C.
  • 1,809
  • 4
  • 24
  • 40

2 Answers2

2

As per the documentation of _.some() method, second argument should be a predicate function

console.log(_.some(array, function(v){ return v === 1234}));


In this particular case you can simply use native javascript Array#indexOf method.
console.log(array.indexOf(1234) > -1);


Also there is native JavaScript Array#some method.
console.log(array.some(function(v){ return v === 1234}));

with ES6 arrow function

console.log(array.some(v => v == 1234))
Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188
  • 1
    There is also ES5 *some* and ECMAScript 2015 arrow functions to give: `array.some(v=>v==1234)`. ;-) – RobG Jun 14 '16 at 10:26
0

With UNDERSCORE.JS you can simply use,

console.log(_.indexOf(array, 1234) >= 0)

Document for more details: http://underscorejs.org/#indexOf

Krishnakant
  • 435
  • 1
  • 6
  • 12