
1. str.indexOf(substring)는 대소문자를 구분합니다. 예를 들어, "Hello"와 "hello"를 비교할 때, 두 문자열은 다른 인덱스를 반환합니다. "Hello"에서 "hello"를 찾을 때, "hello"가 시작되는 인덱스는 -1이 반환됩니다.
2. str.indexOf(substring)는 동일한 문자열이 여러 번 반복되는 경우, 첫 번째 인덱스를 반환합니다. 예를 들어, "hellohello"에서 "hello"를 찾을 때, 첫 번째 "hello"의 인덱스는 0이 반환됩니다.
3. str.indexOf(substring)는 없는 문자열을 찾을 때, -1을 반환합니다. 예를 들어, "hello"에서 "world"를 찾을 때, -1이 반환됩니다.
4. str.indexOf(substring)는 부분 문자열을 찾을 때, 정확한 인덱스를 반환합니다. 예를 들어, "hello world"에서 "world"를 찾을 때, "world"가 시작되는 인덱스는 6이 반환됩니다.
str.indexOf(substring)는 다음과 같은 옵션을 제공합니다.
- str.indexOf(substring, fromIndex): fromIndex부터 시작하여 substring을 찾습니다.
이 옵션을 사용하면, substring이 여러 번 반복되는 경우, 특정 인덱스부터 시작하여 찾을 수 있습니다.
예를 들어, "hellohello"에서 "hello"를 찾을 때, 3부터 시작하여 찾을 수 있습니다.
str.indexOf(substring, fromIndex) 함수는 fromIndex부터 시작하여 substring을 찾습니다. substring이 없을 때, -1을 반환합니다.
str.indexOf(substring)는 대소문자를 구분하고, 동일한 문자열이 여러 번 반복되는 경우, 첫 번째 인덱스를 반환합니다. 없는 문자열을 찾을 때, -1을 반환하고, 부분 문자열을 찾을 때, 정확한 인덱스를 반환합니다.
2025-03-26 06:52