Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

110
Vistas
Is there a way to know the number of characters in a string?

This question concerns unicode characters that are more than one utf-16 character

string.length returns the number of unicode 16 chars in the string. But what about the case of characters that are more than 1 unicode 16 character? Is it possible to get the actual number of characters as well as "true" values from string.charAt of the actual character, and not the utf-16 pieces?

var test = "🀄";
console.log(test.length)
var regex = /[\u{1F000}-\u{1F0FF}]/g;
var regex2 = /🀄/g
console.log('test: ' + regex.test(test));
console.log('test2: ' + regex2.test(test));

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Another option is to use RegExp with the unicode flag.

var test = "🀄";
var length = test.match(/./ug).length;
console.log(length);

Please note that this and the answer using the spread operator can break under certain circumstances.

var test = "Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍A̴̵̜̰͔ͫ͗͢L̠ͨͧͩ͘G̴̻͈͍͔̹̑͗̎̅͛́Ǫ̵̹̻̝̳͂̌̌͘";
var length = test.match(/./ug).length;
console.log(length);

To get the char at a specific index you can use the following function.

var test = "🀄👼👺💩";

var charAt = charAt(test);

console.log(charAt);

function charAt(string, index) {
    if(!index)
        index = 0;

    return string.match(/./ug)[index];
}

about 4 years ago · Juan Pablo Isaza Denunciar

0

you can use spread operator:

var test = "🀄";
var test2 = [...test];
console.log(test.length);
console.log(test2.length);

about your second question, you need to modify regexp:

var test = "🀄";
console.log(test.length)
var regex = /[\u{1F000}-\u{1F0FF}]/ug;
var regex2 = /🀄/g
console.log('test: ' + regex.test(test));
console.log('test2: ' + regex2.test(test));

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda