javascript - angularjs: can't get out loop to check for existing object in array -


if (currentfirstnumber != null && currentsecondnumber != null) {     var card = {         id: rank + "_" + suit,         rank: rank,         suit: suit.tostring()     }; } var exists = false; (i = 0; < $scope.communitycards.length; i++) {     if (card.id == $scope.communitycards[i].id) {         exists = true;         break;     } } if (!exists) {     $scope.communitycards.push(card); } 

i'm trying card object in array of cards, first check if exists because cards generated hash.

if card doesn't exists, everyting goes well. when exists stuck, returns check if exists. while should exit loop , continue parent loop goes trough hash generate new card (not visible here).

 card_ids = $scope.communitycards[i].map(function(card){ return card.id; });  matched_cards = card_ids.filter(function(id){ return id==card.id; });   //check matched_cards.length  //if >0 card exit else not exist   if(matched_cards.length>0){     $scope.communitycards.push(card);  }    //---------------example--------------   = [{t:1}, {t:2}, {t:3}]   c = a.map(function(e){ return e.t; })   d = c.filter(function(e){ return e==2; });   d.length 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -