My apologies if this has been answered here already. I couldn't find a relevant thread.
I'm brand new at JavaScript. I need to be able to truncate a string in a UTF8-friendly way. Currently, using slice() and similar methods, multibyte characters at the end of the string are chopped in half and I get invalid characters.
//Slicing Emojis
var emojitext = "";
var chopped_emoji = emojitext.slice(0, 1);
document.getElementById("slice").innerHTML = chopped_emoji + " is broken";
<p id="slice"></p>
The above code results in an invalid character stored in chopped_emoji. How do I make sure this does not happen?