jquery queries the subscript where the object is located according to the attribute value of the object in the array

//一维数组根据值取下标
var arr = [1,2,4,5]
var proIndex = $.inArray(proid, arr);
//根据数组中对象的属性值查询该对象所在角标
var subArr = [
   {
    
    
      proId:1
      brands:[]
   },   
  {
    
    
      proId:2
      brands:[]
   },  
  {
    
    
      proId:3
      brands:[]
   },
]
 var index = subArr .findIndex(function (item) {
    
     return item.proId === proid; });

Guess you like

Origin blog.csdn.net/qq_39072819/article/details/109843697
Recommended