Sergey Kudryashov
Sergey Kudryashov

Reputation: 723

Underscore.js Get key from value in array

Is there a simple way to get key from value?

var arr = [1,2,3,4,10];
if(_.contains(arr, 3))
  alert(KEY of 3 (2))

Upvotes: 1

Views: 1137

Answers (1)

T.J. Crowder
T.J. Crowder

Reputation: 1074218

  1. Opens documentation

  2. Looks on left

  3. Finds _.indexOf:

_.indexOf(array, value, [isSorted])

Returns the index at which value can be found in the array, or -1 if value is not present in the array.

Upvotes: 4

Related Questions