Fun with JavaScript and Emoji

emoji-spread

Today Wes Bos tweeted a few fun things one can do with JavaScript and Emoji:

  1. It’s possible to spread emoji units (or how are they called?) into their single parts:

    [...'๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ']
    // ["๐Ÿ‘จ", "โ€", "๐Ÿ‘ฉ", "โ€", "๐Ÿ‘ง", "โ€", "๐Ÿ‘ฆ"]
  2. Combining Emoji is also possible:

    ["๐Ÿ‘จ", "โ€", "๐Ÿ‘ฉ", "โ€", "๐Ÿ‘ง"].reduce((prev, curr) => prev + curr)
    // "๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘ง"
  3. And oh, you can even replace single emoji within emoji units, yielding a new emoji unit:

    '๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘ฆ'.replace(/๐Ÿ‘ฉ/g, '๐Ÿ‘จ')
    // "๐Ÿ‘จโ€๐Ÿ‘จโ€๐Ÿ‘ฆ"
  4. This kind of sorcery also works with skin tone modifiers by the way:

    [...'๐Ÿ›€๐Ÿพ']
    // ["๐Ÿ›€", "๐Ÿพ"]
    
    ["๐Ÿ›€", "๐Ÿพ"].reduce((prev, curr) => prev + curr)
    // "๐Ÿ›€๐Ÿพ"
    
    '๐Ÿ›€๐Ÿพ'.replace("๐Ÿพ", "")
    // "๐Ÿ›€"

Geekfun! ๐ŸŒˆ

Elsewhere ,

2 Responses to Fun with JavaScript and Emoji

  1. Pingback: Fun with JavaScript and emoji - murze.be

  2. Pingback: runes โ€“ Unicode-aware JS string splitting with full Emoji support | Bram.us

Leave a Reply

Your email address will not be published. Required fields are marked *