Search code examples
javascriptunicodehexemoji

Wrong emoji unicode


When I want to convert this emoji: 😶‍🌫️ I get only a part of the wanted unicode: U+1f636 instead of U+1F636U+200DU+1F32BU+FE0F

I tried using String.prototype.codePointAt(0).toString(16) But it give me "1f636" (not the thing I want) In JavaScript


Solution

  • You are only partially there .. String.prototype.codePointAt(0).toString(16) will give you the correct Uni for the first codepoint ( index[0] ), but you'll need to map through ALL the codepoints that make up said emoji:

    const emoji = "😶‍🌫️" 
    
    const emoji_uni = "U+" + [...emoji].map(
       e => e.codePointAt(0).toString(16)
    ).join('+').toUpperCase()
    
    console.log(emoji_uni)

    Because your OP was specific -- I

    1. added toUppercase()
    2. pre-pended the string with U+
    3. used .join() to join as a string and add your + denotations

    Which will result in U+1F636+200D+1F32B+FE0F