js determines whether there is a character in the string string?

Vue.filter('howManyPeopleDiff', function (str) {
    
    
  var perNum='';
  if(str.search("1") != -1){
    
    
    perNum+= 'a'
  }
  if(str.search("2") != -1){
    
    
    perNum+= 'b'
  }
  if(str.search("3") != -1){
    
    
    perNum += 'c'
  }
  if(str.search("4") != -1){
    
    
    perNum += 'd'
  }
  if(str.search("5") != -1){
    
    
    perNum+= 'e'
  }
  if(str.search("6") != -1){
    
    
    perNum+= 'f'
  }
  return perNum;
});

return perNumThe return value of · For example,

  • For example (call and corresponding return):,
    {(1,2) | howManyPeopleDiff}// return ab
    {(3,4) | howManyPeopleDiff}, // return cd
    {(1,2,3,4) | howManyPeopleDiff}// returnabcd
  • and many more;

  • Blogger's own retention: call method, see the code file corresponding to the remark project file for details.


The above is all about "js judges whether the string contains a certain character? ".

Guess you like

Origin blog.csdn.net/qq_35393869/article/details/108538832