Metode JavaScript virkne fromCodePoint () atgriež virkni, kas izveidota, izmantojot norādīto kodu punktu secību.
Metodes sintakse fromCodePoint()
ir šāda:
String.fromCodePoint(num1,… , numN)
fromCodePoint()
Metodi, kas ir statiska metode, sauc izmantojot String
klases nosaukumu.
fromCodePoint () parametri
fromCodePoint()
Metode ņem in:
- num1,…, numN - kodu punktu secība.
Atgriezt vērtību no fromCodePoint ()
- Atgriež virkni, kas izveidota, izmantojot norādīto kodu punktu secību.
Piezīmes :
fromCodePoint()
Metode throwsRangeError
ja nederīgs Unicode kodu punktu dots.fromCodePoint()
Metode atgriež virkni, un nevisString
objektu.
Piemērs: Izmantojot metodi fromCodePoint ()
let string1 = String.fromCodePoint(65, 66, 67); console.log(string1); // ABC let string2 = String.fromCharCode(72, 69, 76, 76, 79); console.log(string2); // HELLO // numbers can be passed as hexadecimals let string3 = String.fromCodePoint(0x2f804); console.log(string3); // "uD87EuDC04" // unlike fromCharCode() that requires surrogate pair to return supplementary char // fromCodePoint() can even return 4-byte supplementary chars let string4 = String.fromCodePoint(0x1f303); console.log(string4); // Unicode character "Night with Stars" let string5 = String.fromCodePoint(Infinity); console.log(string5); // RangeError
Rezultāts
ABC HELLO uD87E uDC04 RangeError: Nederīgs koda punkts Bezgalība
Ieteicams lasīt: JavaScript virkne fromCharCode ()