您的位置:首页 > Web前端 > JavaScript

underscore.js _.lastIndexOf[Array]

2012-04-15 23:39 351 查看
Returns the index of the last occurrence of value in the array, or -1 if value is not present. Uses the native lastIndexOf function if possible

返回值在数组中最后出现的位置,如果没有出现,返回-1

_.lastIndexOf([1, 2, 3, 1, 2, 3], 2);
=> 4


源码:

_.lastIndexOf = function(array, item) {
if (array == null) return -1;
if (nativeLastIndexOf && array.lastIndexOf === nativeLastIndexOf) return array.lastIndexOf(item);
var i = array.length;
while (i--) if (i in array && array[i] === item) return i;
return -1;
};
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: