Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 7월.
Array 인스턴스의 indexOf() 메서드는 배열에서 주어진 요소를 찾을 수 있는 첫 번째 인덱스를 반환하고, 찾을 수 없는 경우 -1을 반환합니다.
배열에서 위치를 찾을 요소입니다.
fromIndex Optional검색을 시작할 0 기반 인덱스로, 정수로 변환됩니다.
배열에서 searchElement의 첫 번째 인덱스이고, 찾을 수 없으면 -1입니다.
indexOf() 메서드는 엄격한 동등성을 사용하여 배열의 요소와 searchElement를 비교합니다(=== 연산자가 사용하는 것과 동일한 알고리즘). NaN 값은 절대 동일하게 비교되지 않으므로, searchElement가 NaN인 경우 indexOf()는 항상 -1을 반환합니다.
indexOf() 메서드는 희소 배열의 빈 슬롯을 건너뜁니다.
indexOf() 메서드는 범용입니다. this 값에는 length 속성과 정수 키 속성만 있을 것으로 예상합니다.
다음 예제는 indexOf()를 사용하여 배열에서 값을 찾습니다.
indexOf()를 사용하여 NaN을 검색할 수 없습니다.
indexOf()를 사용하여 희소 배열에서 빈 슬롯을 검색할 수 없습니다.
indexOf() 메서드는 this의 length 속성을 읽은 다음 키가 length보다 작은 음수가 아닌 정수인 각 속성에 접근합니다.
| ECMAScript® 2027 Language Specification # sec-array.prototype.indexof |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025년 10월 10일 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.