xxxxxxxxxx
const str = "Hello World";
const characterCount = str.length;
console.log(characterCount);
xxxxxxxxxx
const string = "Hello world"
const charCount = string.length //11
const charCountWithoutWhitespace = string.replace(/\s/g, '').length //10
const wordCount = string.split(/\s+/).length //2
const paragraphCount = string.replace(/\n$/gm, '').split(/\n/).length //1
xxxxxxxxxx
var str = "Hello, world 123!";
var regex = /[^0-9]/g; // only count letters
console.log(str.replace(regex, "").length); // replaces numbers to empty char and counts length
// prints 10 to the console