Underscore.js 从数组中的值获取键
Underscore.js Get key from value in array
是否有从值中获取键的简单方法?
var arr = [1,2,3,4,10];
if(_.contains(arr, 3))
alert(KEY of 3 (2))
左看
找到 _.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.
是否有从值中获取键的简单方法?
var arr = [1,2,3,4,10];
if(_.contains(arr, 3))
alert(KEY of 3 (2))
左看
找到
_.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.