`String.prototype.trimStart` 및 `String.prototype.trimEnd`
· 약 1분
ES2019에서는 String.prototype.trimStart()
및 String.prototype.trimEnd()
을 소개합니다:
const string = ' hello world ';
string.trimStart();
// → 'hello world '
string.trimEnd();
// → ' hello world'
string.trim(); // ES5
// → 'hello world'
이 기능은 이전에 비표준 메서드인 trimLeft()
와 trimRight()
를 통해 제공되었습니다. 이러한 메서드는 새로운 메서드와의 호환성을 위해 여전히 별칭으로 남아 있습니다.
const string = ' hello world ';
string.trimStart();
// → 'hello world '
string.trimLeft();
// → 'hello world '
string.trimEnd();
// → ' hello world'
string.trimRight();
// → ' hello world'
string.trim(); // ES5
// → 'hello world'