html show only first 10 characters of html page code example
Example 1: js get first 3 characters of string
const string = "0123456789";
console.log(string.slice(0, 2));
console.log(string.slice(0, 8));
console.log(string.slice(3, 7));
Example 2: max char js
function maxChar(str) {
let charCountObj = {};
let maxChar = "";
let maxCount = 0;
for (let i = 0; i < str.length; i++) {
const char = str[i];
charCountObj[char] = charCountObj[char] + 1 || 1;
if (charCountObj[char] > maxCount) {
maxChar = char;
maxCount = charCountObj[char];
}
}
return maxChar;
}