JavaScript: Count Chars in String 🚀

By Xah Lee. Date: . Last updated: .
/* [
xah_string_char_count(str)
return number of chars in string str.
http://xahlee.info/js/js_string_byte_sequence.html
URL http://xahlee.info/js/js_string_real_length.html
Version 2018-06-17 2022-10-18
] */
const xah_string_char_count = ((str) => {
  let i = 0;
  for (let c of str) {
    i += 1;
  }
  return i;
});

// --------------------------------------------------
// test
console.log(xah_string_char_count("😂") === 1);

JavaScript String

BUY
ΣJS
JavaScript in Depth