angularjs - Filter json collection by id in Javascript -


so i'm trying retrieve collection list below id in javascript. how can that? i've been searching lately find way couldn't.

   {'id':1,"firstteam":"barcelona","secondteam":"real       madrid","time":"14:00","commentator":"unknown","championship":"uefa","channel":"bein sport","iframe":'<iframe width="560" height="315" src="https://www.youtube.com/embed/pqro_5dtqrk" frameborder="0" allowfullscreen></iframe>'}     {'id':2,"firstteam":"barcelona","secondteam":"real madrid","time":"14:00","commentator":"unknown","championship":"uefa","channel":"bein sport","iframe":'<iframe width="560" height="315" src="https://www.youtube.com/embed/pqro_5dtqrk" frameborder="0" allowfullscreen></iframe>'} 

use array.prototype.filter():

 var testarray = [{'id':1,"firstteam":"barcelona","secondteam":"real madrid","time":"14:00","commentator":"unknown","championship":"uefa","channel":"bein sport","iframe":'<iframe width="560" height="315" src="https://www.youtube.com/embed/pqro_5dtqrk" frameborder="0" allowfullscreen></iframe>'}, {'id':2,"firstteam":"barcelona","secondteam":"real madrid","time":"14:00","commentator":"unknown","championship":"uefa","channel":"bein sport","iframe":''}];  var filtered = testarray.filter(filterfunction);  // let's assume want filter id, stored in $scope variable. $scope.filterbyid = 2;   function filterfunction(val) {   return value.id == $scope.filterbyid; } 

Comments

Popular posts from this blog

authentication - Mongodb revoke acccess to connect test database -

r - Update two sets of radiobuttons reactively - shiny -

ios - Realm over CoreData should I use NSFetchedResultController or a Dictionary? -