String Method

ES6에서는 다양한 string method가 추가되었다.

String.prototype.includes()

const isEmail = (email) => email.includes("@");

console.log(isEmail("rheeeuro@gmail.com"));

true


String.prototype.repeat()

const list = "<li>item</li>\n".repeat(5);

console.log(list);
<li>item</li>
<li>item</li>
<li>item</li>
<li>item</li>

String.prototype.startsWith()

const isUrl = (url) => url.startsWith("https://");

console.log(isUrl("https://github.com/rheeeuro"));

true


String.prototype.endsWith()

const isGmail = (url) => url.endsWith("@gmail.com");

console.log(isGmail("rheeeuro@gmail.com"));

true