[ES6+] String을 사용하는 다양한 방법들! (includes, repeat, startsWith, endsWith)


includes()

지정한 문자열이 포함되어있는지 확인하는 메소드

const isEmail = (email) => email.includes("@")
console.log(isEmail("wlthfk0211@gmail.com"));
//true

repeat()

원하는 만큼 반복하는 메소드

const CC_number = "7070";
const displayName = `${"*".repeat(10)}${CC_number}`;
console.log(displayName);
//**********7070

startsWith() , endsWith()

지정한 문자열로 시작/끝 인지 확인해주는 메소드

const name = "Ms.Ji"
console.log(name.startsWith("M"));
//true





노마드코더의 ‘ES6의 정석’을 듣고 정리 =)




© 2018. by sora

Powered by sora