Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

163
Views
cannot get utf8 icon with charAt js

let a=["😍"] ; let b="😍"

console.log(a[0],b,b.charAt(0))

"😍" "😍" "�"

this charAt prints questions mark ... can someone enlighten me how to get utf8 icon with charAt in a string

about 4 years ago Β· Juan Pablo Isaza
1 answers
Answer question

0

Emojis are represented using multiple bytes:

let b="😍"
console.log(b.length)

With charAt you only get one part of the emoji.

With codePoint you can get the:

a non-negative integer that is the Unicode code point value at the given position.

You however need to know where the emojii starts at, because the index itself still refers to the bytes:

let b="πŸ˜πŸ‘†πŸ‘"
console.dir(String.fromCodePoint(b.codePointAt(0)));
console.dir(String.fromCodePoint(b.codePointAt(2)));

You could split your string using the spread operator ... and then access the visible char in question using the index. This works because the iterator uses the code points and not individual bytes.

let b="😍testπŸ‘†testπŸ‘"

function splitStringByCodePoint(str) {
  return [...str]
}

console.log(splitStringByCodePoint(b)[5])

But that won't work with emojis like πŸ‘†πŸ½ because those consist of πŸ‘† + byte(s) representing the variation (color).

let b="πŸ‘†πŸ½"
console.log(b.length)
function splitStringByCodePoint(str) {
  return [...str]
}

console.log(splitStringByCodePoint(b))
console.log(String.fromCodePoint(b.codePointAt(0)));
console.log(String.fromCodePoint(b.codePointAt(2)));

If you want to support all emojis you currently need to write your own parser or look for a library that does that.

about 4 years ago Β· Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
Β© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!