어떠한 조건을 판별하는 기준을 만드는 것
//조건문 쓰기
//조건에는 Boolean으로 결과가 나오는 표현식
if (조건1) { //조건1이 통과할 경우
} else if (조건2) { //조건1이 통과하지 않고 조건 2가 통과할 경우
} else { //모든 조건이 통과하지 않는 경우
}
//삼항 연산자 구문 표현
(조건) ? value1 : value2
(조건) ? value1 : (value2 : value3)
비교 연산자(Comparison operator)
논리 연산자(Logical Operator)
let word = ‘StrawBerry’ ;
console.log(word[0]); // 'S'
console.log(word[5]); // 'B'
console.log(word[15]); // undefined
index로만 사용할 수 있음 (read-only)
word[0] = 'C';
console.log(word); // 여전히 'StrawBerry'
purpose) 찾고자 하는 문자열의 index 찾기
return) 처음으로 일치하는 index를 보임, 찾고자 하는 문자열이 없으면 -1
c.f) str.lastindexOf(searchValue) 뒤에서부터 찾기
let word = 'Pink Bear';
word.indexOf('Pink'); //0
word.indexOf('Bear'); //5
word.indexOf('Blue'); //-1
let word1 = 'Pink Bear Bear';
word1.indexOf('Bear'); //5
'flexible'.lastIndexOf('l'); //6
c.f) str.includes(searchValue) : T/F 형태로 반환
문자열을 분리 기준에 맞게 분리된 문자열이 포함된 배열로 바꾸기
let sentence = 'It was good to see you again';
console.log(sentence.split(' '));
//['It', 'was', 'good', 'to', 'see', 'you', 'again']
str.split(’\n’) : 줄바꿈 기준으로 분리
let greeting = ' hello world! ';
console.log(greeting); //' hello world! '
console.log(greeting.trim()); //'hello world!'
더 알아볼 기능
? match
?replace
? 정규 표현식