string.length
const str = '๊ณ ์์ด ์ต๊ณ ์';
str.length; // 7Syntax
string.lengthDescription
Unicode
function getCharacterLength (str) {
// ์ฌ๊ธฐ์ ์ฌ์ฉ๋๋ ๋ฌธ์์ด ์ํ๋ ๋จ์ํ ์ฝ๋ ๋จ์๊ฐ ์๋๋ผ ๋ฌธ์ ์์์ ์ํํ๋ค.
return [...str].length; // ๐ง ๋ฐฐ์ด์ ์์๋ก ๋ง๋ ํ ๊ทธ length
}
console.log(getCharacterLength('A\uD87E\uDC04Z')) // 3
// ๊ถ์ฅํ์ง ์์ง๋ง ๋ค์๊ณผ ๊ฐ์ด ์ถ๊ฐํ ์ ์๋ค.
Object.defineProperty(String.prototype, 'charLength', {
get () {
return getCharacterLength(this);
}
});
console.log('A\uD87E\uDC04Z'.charLength); // 3Examples
length ํ ๋นํ๊ธฐ
Last updated