자바스크립트 ES6 String Methods

  • [String.prototype.startsWith()][https://developer.mozilla.org/ko/docs/web/javascript/reference/global_objects/string/startswith]

    • 문자열이 특정 문자로 시작하는지 확인, 결과를 true, false로 반환.
  • [String.prototype.endsWith()][https://developer.mozilla.org/ko/docs/web/javascript/reference/global_objects/string/endswith]

    • 문자열이 특정 문자로 끝나는지 확인, 결과를 true, false로 반환.
  • [String.prototype.includes()][https://developer.mozilla.org/ko/docs/web/javascript/reference/global_objects/string/includes]

    • 문자열에 특정 문자열이 포함되는지 확인, 결과를 true, false로 반환.
let str = 'javascript es6 string methods';

console.log(str.startsWith('javascript')); //true
console.log(str.endsWith('methods')); //true
console.log(str.includes('es6')); //true
  • [String.prototype.repeat()][https://developer.mozilla.org/ko/docs/web/javascript/reference/global_objects/string/repeat]

    • 문자열을 인자만큼 반복하는 문자열을 반환
let str = 'es6';

console.log(str.repeat(3)); //es6es6es6

Reference