How to remove all emojis from a string if they are not equal to any of the ones in the object?
For example:
let allowedEmojis = {
'😀': 50,
'😂': 150,
'🥳': 500
};
function filterEmojis() {
// what should I type here?
}
let str = "Helloo 😀😂🥳😡";
str = filterEmojis(str);
console.log(str); // Helloo 😀😂🥳
2
Answers
The regex might not pass for all Emojis but this is a simple solution to the problem.
Another, simpler, solution would be to use the callback functionality of
String.replace()
: