반응형
문자열 메서드 : charAt()
match() 메서드는 문자열에서 특정 인덱스에 위치하는 유니코드 단일문자를 반환합니다.
"문자열".charAt("위치값");
const str1 = "javascript reference";
const currentStr1 = str1.charAt(); // j
const currentStr2 = str1.charAt("0"); // j
const currentStr3 = str1.charAt("1"); // a
const currentStr4 = str1.charAt("2"); // v
charAt() 예제
var anyString = 'Brave new world';
console.log("The character at index 0 is '" + anyString.charAt() + "'");
// No index was provided, used 0 as default
console.log("The character at index 0 is '" + anyString.charAt(0) + "'");
console.log("The character at index 1 is '" + anyString.charAt(1) + "'");
console.log("The character at index 2 is '" + anyString.charAt(2) + "'");
console.log("The character at index 3 is '" + anyString.charAt(3) + "'");
console.log("The character at index 4 is '" + anyString.charAt(4) + "'");
console.log("The character at index 999 is '" + anyString.charAt(999) + "'");
결과 확인하기
The character at index 0 is 'B'
The character at index 1 is 'r'
The character at index 2 is 'a'
The character at index 3 is 'v'
The character at index 4 is 'e'
The character at index 999 is ''
The character at index 1 is 'r'
The character at index 2 is 'a'
The character at index 3 is 'v'
The character at index 4 is 'e'
The character at index 999 is ''
반응형
댓글