Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript count occurrences of letter in string

function count(str, find) {
    return (str.split(find)).length - 1;
}

count("Good", "o"); // 2
Comment

how to count specific letters in string js

console.log(("str1,str2,str3,str4".match(/,/g) || []).length); //logs 3

console.log(("str1,str2,str3,str4".match(new RegExp("str", "g")) || []).length); //logs 4
Comment

PREVIOUS NEXT
Code Example
Javascript :: socket.io client send data node js server 
Javascript :: how to access dictionary keys in js 
Javascript :: random number generator javascript with range 
Javascript :: how to use a specific node version for inside a folder 
Javascript :: how remove the spaces from the string, then return the resultant string 
Javascript :: how to unban in discord js 
Javascript :: get domain name with regex 
Javascript :: js html tag valu 
Javascript :: get top window url from iframe 
Javascript :: check upload img extension jquery 
Javascript :: how to remove a specific element from array in javascript 
Javascript :: kebab case javascript 
Javascript :: dm command discord.js 
Javascript :: string indexing in js 
Javascript :: complete math objects in javascript 
Javascript :: how to set emmet for jsx in visual studio code 
Javascript :: mongodb mongoose update an element in an array of objects 
Javascript :: how is javascript compiled 
Javascript :: javascript fibonacci example 
Javascript :: node filesystem change directory of a file 
Javascript :: javasript document referrer 
Javascript :: datatables get all checkboxes with pagination 
Javascript :: socket io emit to socket id 
Javascript :: find a word in string javascript 
Javascript :: youtube set speed command 
Javascript :: nodemailer, mailer, nodemailer npm 
Javascript :: remove selected js 
Javascript :: switch alert 
Javascript :: deduplicate array javascript 
Javascript :: how to create package.json file in vs code 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =