Filter array of objects that contains string using lodash

后端 未结 3 1010
甜味超标
甜味超标 2021-02-12 13:15

I have a value and i need to return the objects that contains this value in propertie.

var search=\'CPP@\';
var results=_.filter(collection,{VAL:search});
         


        
3条回答
  •  温柔的废话
    2021-02-12 13:35

    var collection=[
      {
        "DSP_MAQ": "Máquina 4",
        "VAL": "CPP@4@1900-01-01"
      },
      {
        "DSP_MAQ": "Máquina 5",
        "VAL": "CMIP@5@1900-01-01"
      },
      {
        "DSP_MAQ": "Máquina 6",
        "VAL": "CMIP@6@1900-01-01"
      },
      {
        "DSP_MAQ": "Máquina 7",
        "VAL": "CMIP@7@1900-01-01"
      },
      {
        "DSP_MAQ": "Máquina 8",
        "VAL": "CPP@8@1900-01-01"
      },
      {
        "DSP_MAQ": "Máquina 9",
        "VAL": "CMIP@9@1900-01-01"
      },
      {
        "DSP_MAQ": "Máquina 10",
        "VAL": "CMIP@10@1900-01-01"
      }
     
    ];
     var search='CPP@';
        var results=_.filter(collection,function(item){
        return item.VAL.indexOf(search)>-1;
        });
        console.log(results);

     var search='CPP@';
        var results=_.filter(collection,function(item){
        return item.VAL.indexOf(search)>-1;
        });
        console.log(results);
    

提交回复
热议问题