Let's say I have a string as such:
var text = "Hi ";
I want to store this text in a database and wish to convert the emoji's to unicode.
My current solution is to convert the string to an array. Then convert each character to unicode.
function toUnicode(text){
var arr = Array.from(text);
var unicodeArr = [];
for (let i = 0; i < arr.length; i++) {
var unicode = arr[i].codePointAt(0).toString(16);
unicodeArr.push(unicode);
}
return JSON.stringify(unicodeArr);
}
Here are the output when I run the code:
var text = "Hi ";
var unicodeArr = toUnicode(text);
console.log(unicodeArr); //["48","69","20","1f602","1f602"]
The only issue is that I'm not sure how to convert this back to a whole string.
Is there a much more easy solution to store this var text = "Hi ";
in a Database?