JavaScript(JS) string method - fromcodepoint
The fromCodePoint()
method is a static method in JavaScript's String object, which is used to create a string from a sequence of Unicode code point values.
Here's the syntax for the fromCodePoint()
method:
String.fromCodePoint(num1, num2, ..., numN)
Here, num1
, num2
,..., numN
are the Unicode code point values of the characters that you want to include in the resulting string.
For example, let's say you have a series of Unicode code point values representing the characters "H", "e", "l", "l", "o":
let codePointVals = [72, 101, 108, 108, 111];
You can use the fromCodePoint()
method to convert these code point values into a string:
let str = String.fromCodePoint(...codePointVals); console.log(str); // Output: "Hello"
The spread operator ...
is used to pass the array of Unicode code point values as individual arguments to the fromCodePoint()
method.
Note that the fromCodePoint()
method is a static method, which means that it is called on the String object itself, rather than on an instance of a string.