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)); // "01"
console.log(string.slice(0, 8)); // "01234567"
console.log(string.slice(3, 7)); // "3456"

Example 2: max char js

function maxChar(str) {
  let charCountObj = {};
  let maxChar = "";
  let maxCount = 0;

  //  Fill out CharCountObj
  //  Updates new MaxCount

  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;
}