seantrant
10/2/2017 - 2:48 PM

Filter and map a json array

Filter and map a json array

this.cells = this.cells.filter(function(smallify) {
    return smallify.side == 1; // if truthy then keep item
}).map(function(smallify) {
    return { // return what new object will look like
        name: smallify.name
    };
});

// another example with angular subscription 

this._wmsService.getStations()
   .subscribe(
      res =>
      {
         this.stations = res.map(m => { return { name: m.name, value: m.id } })
      },
      error => {})
}