MaxBeauchemin
1/3/2018 - 2:50 PM

Javascript Filter

Filter allows you to narrow down the results of a collection that match a certain criteria

var records = [
  {Id: 1, Active: true},
  {Id: 2, Active: false},
  {Id: 3, Active: true}
];

var activeRecords = records.filter(function(rec){
  if(rec.Active){
    return rec;
  }
});

//console.log(activeRecords) ==> [{Id: 1, Active: true},{Id: 3, Active: true}]