Issue
I need a response from a public API that contains the letter ø (\u00f8). I'm using angular, and I use an interface to make my responses typed.
export interface Response{
øl: string; // instead of ø I would like to use \u00f8 (or something similiar)
}
The problem is I have some international coworkers that do not have ø in their alphabet. Creating strings with Unicode is easy, but how can I do it with property names?
Solution
The answer is "Yes they can use unicode entities instead of the characters they cannot type"
In your case they could use \u00F8 for ø
const response = {
"øl":"🍺",
"b\u00C6":"💩",
"💩": "b\u00E6",
"f\u00F8l": "🐎"
}
console.log(response["\u00F8l"])
console.log(response["øl"])
console.log(response["💩"])
console.log(response["føl"])
console.log(Object.entries(response)
.filter(([key,value]) => key.includes("\u00F8")))
console.log(Object.entries(response)
.filter(([key,value]) => key.includes("ø")))
Answered By - mplungjan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.