lodash 源码解读 _.findIndex(obj_array, fn)

 _.findIndex(obj_array, fn), 从对象数组中返回满足条件的第一个对象,如果没有返回-1

var users = [
    { 'user': 'barney',  'active': 1 },
    { 'user': 'fred',    'active': 1 },
    { 'user': 'pebbles', 'active': 2 },
    { 'user': 'pebbles', 'active': 1 }
  ];
  var s = _.findIndex(users, function(o){return o.user=='fred'})
  console.log(s); // 1

 

posted on 2017-06-02 15:32  bbb324  阅读(138)  评论(0编辑  收藏  举报

导航