Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Javascript count instances of character in a string

 function countInstancesOf(letter, sentence) {
  var count = 0;

  for (var i = 0; i < sentence.length; i++) {
    if (sentence.charAt(i) === letter) {
      count += 1;
    }
  }
  return count;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: nodejs wait function 
Javascript :: js classlist 
Javascript :: convert base64 to image nodejs 
Javascript :: javascript add function to onchange event 
Javascript :: js get vh value 
Javascript :: innertext vs textcontent 
Javascript :: concat array of objects javascript 
Javascript :: cypress click link contains text 
Javascript :: get days in current month using moment.js 
Javascript :: request body empty express 
Javascript :: vscode js brackets not close 
Javascript :: bignumber to number javascript 
Javascript :: knex.js count 
Javascript :: set focus on load javascript 
Javascript :: where to place async in const function 
Javascript :: js form serialize 
Javascript :: to capital case javascript 
Javascript :: react native scrollable 
Javascript :: Check ratelimit discord js 
Javascript :: javascript while 
Javascript :: javascript negative infinity 
Javascript :: minecraft lang file 
Javascript :: json javascript 
Javascript :: how to submit form using ajax 
Javascript :: how to get innerhtml value in javascript 
Javascript :: react disable eslint errors 
Javascript :: js regex with variable 
Javascript :: loop through files in directory javascript 
Javascript :: how to align text vertically center beside an image in react native 
Javascript :: divide first name and last name in javascript 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =