javascript - If statement checks regardless of the case of the letters -


i want make if statement flexible. if input exact info in input box, statement triggers if user put in lower case or uppercase cannot detected. here codes.

var find = _.findwhere($scope.allcast, {name: castname});             if(!find){                 var cast = {                     cpportfolioitemid: id,                     name: castname,                     job: 'cast',                     role: castrole                 };                 contentassessmentfactory.addcastdetail(cast);             }else{                 $window.alert('cast name exist.');             } 

any appreciated.

you can use _.filter() converting cast.name , castname in lower or upper case.

//return array of matched elements var find = _.filter($scope.allcast, function(cast){     //convert both text in lower case , compare     //if required can use .trim() castname.trim().tolowercase() strip whitespace      return cast.name.tolowercase() == castname.tolowercase(); });  if(find.length == 0){     var cast = {         cpportfolioitemid: id,         name: castname,         job: 'cast',         role: castrole     };     contentassessmentfactory.addcastdetail(cast); }else{     $window.alert('cast name exist.'); } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -