| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/zh/docs/Web/JavaScript/Reference/Global_Objects/String/normalize | [Back] [Original] |
Get to know MDN better
const name1 = "\u0041\u006d\u00e9\u006c\u0069\u0065";
const name2 = "\u0041\u006d\u0065\u0301\u006c\u0069\u0065";
console.log(`${name1}, ${name2}`);
// Expected output: "Amlie, Amlie"
console.log(name1 === name2);
// Expected output: false
console.log(name1.length === name2.length);
// Expected output: false
const name1NFC = name1.normalize("NFC");
const name2NFC = name2.normalize("NFC");
console.log(`${name1NFC}, ${name2NFC}`);
// Expected output: "Amlie, Amlie"
console.log(name1NFC === name2NFC);
// Expected output: true
console.log(name1NFC.length === name2NFC.length);
// Expected output: true
normalize()
normalize(form)
Unicode
RangeError form
Unicode "A" U+0041 ""
"n" U+006EU+0303const string1 = "\u00F1";
const string2 = "\u006E\u0303";
console.log(string1); //
console.log(string2); //
const string1 = "\u00F1"; //
const string2 = "\u006E\u0303"; //
console.log(string1 === string2); // false
console.log(string1.length); // 1
console.log(string2.length); // 2
normalize()
Unicode
normalize() "NFD" "NFC" ""
let string1 = "\u00F1"; //
let string2 = "\u006E\u0303"; //
string1 = string1.normalize("NFD");
string2 = string2.normalize("NFD");
console.log(string1 === string2); // true
console.log(string1.length); // 2
console.log(string2.length); // 2
"NFD" 2 "NFD" "" "\u006E\u0303"
"NFC" "" "\u00F1"
let string1 = "\u00F1"; //
let string2 = "\u006E\u0303"; //
string1 = string1.normalize("NFC");
string2 = string2.normalize("NFC");
console.log(string1 === string2); // true
console.log(string1.length); // 1
console.log(string2.length); // 1
console.log(string2.codePointAt(0).toString(16)); // f1
Unicode
normalize() "NFKD" "NFKC"
let string1 = "\uFB00";
let string2 = "\u0066\u0066";
console.log(string1); //
console.log(string2); // ff
console.log(string1 === string2); // false
console.log(string1.length); // 1
console.log(string2.length); // 2
string1 = string1.normalize("NFKD");
string2 = string2.normalize("NFKD");
console.log(string1); // ff <-
console.log(string2); // ff
console.log(string1 === string2); // true
console.log(string1.length); // 2
console.log(string2.length); // 2
"f"
"NFKD" "NFKC"
//
// U+1E9B: S
// U+0323:
const str = "\u1E9B\u0323";
// NFC
// U+1E9B: S
// U+0323:
str.normalize("NFC"); // '\u1E9B\u0323'
str.normalize(); //
// NFD
// U+017F: S
// U+0323:
// U+0307:
str.normalize("NFD"); // '\u017F\u0323\u0307'
// NFKC
// U+1E69: S
str.normalize("NFKC"); // '\u1E69'
// NFKD
// U+0073: S
// U+0323:
// U+0307:
str.normalize("NFKD"); // '\u0073\u0323\u0307'
| ECMAScript 2027 LanguageSpecification # sec-string.prototype.normalize |
StringString.prototype.anchor()String.prototype.at()String.prototype.big()String.prototype.blink()String.prototype.bold()String.prototype.charAt()String.prototype.charCodeAt()String.prototype.codePointAt()String.prototype.concat()String.prototype.endsWith()String.prototype.fixed()String.prototype.fontcolor()String.prototype.fontsize()String.prototype.includes()String.prototype.indexOf()String.prototype.isWellFormed()String.prototype.italics()String.prototype.lastIndexOf()String.prototype.link()String.prototype.localeCompare()String.prototype.match()String.prototype.matchAll()String.prototype.normalize()String.prototype.padEnd()String.prototype.padStart()String.prototype.repeat()String.prototype.replace()String.prototype.replaceAll()String.prototype.search()String.prototype.slice()String.prototype.small()String.prototype.split()String.prototype.startsWith()String.prototype.strike()String.prototype.sub()String.prototype.substr()String.prototype.substring()String.prototype.sup()String.prototype.toLocaleLowerCase()String.prototype.toLocaleUpperCase()String.prototype.toLowerCase()String.prototype.toString()String.prototype.toUpperCase()String.prototype.toWellFormed()String.prototype.trim()String.prototype.trimEnd()String.prototype.trimStart()String.prototype.valueOf()String.prototype[Symbol.iterator]()Object/FunctionObject.prototype.__defineGetter__()Object.prototype.__defineSetter__()Object.prototype.__lookupGetter__()Object.prototype.__lookupSetter__()Object.prototype.hasOwnProperty()Object.prototype.isPrototypeOf()Object.prototype.propertyIsEnumerable()Object.prototype.toLocaleString()Object.prototype.toString()Object.prototype.valueOf()| Web Proxy Viewer | New URL | Original Page |