How can I find the index of an object inside a Array using underscore.js?

前端 未结 7 799
滥情空心
滥情空心 2021-02-14 07:45

I want to get the index of the given value inside a Array using underscore.js.

Here is my case

var array = [{\'id\': 1, \'name\': \'xxx\'},
                      


        
7条回答
  •  感动是毒
    2021-02-14 08:28

    _.find(array, function(item, index) {
      if (item.id == searchValue.id) {
        alert(index);
      }
    });
    

提交回复
热议问题