Find index in array of objects

后端 未结 4 2180
梦如初夏
梦如初夏 2021-01-18 15:54

I would like to find index in array. Positions in array are objects, and I want to filter on their properties. I know which keys I want to filter and their values. Problem i

4条回答
  •  梦谈多话
    2021-01-18 16:27

    here is thefiddle hope it helps you

     for(var intIndex=0;intIndex < data.length; intIndex++){
      eachobj = data[intIndex];
    var flag = true;
     for (var k in filterparams) {
    
        if (eachobj.hasOwnProperty(k)) {
            if(eachobj[k].toString() != filterparams[k].toString()){
               flag = false;
            }
        }
    }
    if(flag){
           alert(intIndex);
    }
    

    }

提交回复
热议问题