includes() 메서드는 하나의 문자열이 다른 문자열에 포함되어 있는지를 판별하고, 결과를 true 또는 false 로 반환합니다.
const sentence = 'The quick brown fox jumps over the lazy dog.';
const word = 'fox';
console.log(`The word "${word}" ${sentence.includes(word) ? 'is' : 'is not'} in the sentence`);
// expected output: "The word "fox" is in the sentence"
예제에서 입력한 값에 필수들어가야하는 값을 찾기 위해서 사용 되었습니다.
function emailFormatTest() {
let val = document.getElementById('input-q2').value;
if(val.includes('@')){
let last = val.split('@')[1].split('.')
alert(last[0])
val = ""
}else{
alert('이메일 형식이 아닙니다')
};
}
'프론트엔드 > Javascript' 카테고리의 다른 글
17번 문제 문자열 다루기 기본 (0) | 2021.11.08 |
---|---|
jquery ajax 통신 (0) | 2021.11.06 |
axios을 사용한 http 비동기 통신 (0) | 2021.10.12 |
제이쿼리 Ajax (0) | 2021.10.11 |
split('') (0) | 2021.10.11 |