배열 요소 값을 가지고 배열의 인덱스를 찾는다.
Array.indexOf(searchStr, starindex);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
let fruits = ["apple","pear","orange","apple"];
document.write(fruits.indexOf("apple")+ "<br>");
document.write(fruits.indexOf("ap") + "<br>");
document.write(fruits.indexOf("apple",2) + "<br>") // 2번째 요소부터 찾는다.
</script>
</body>
</html>
'웹 프로그래밍 기초 > 객체' 카테고리의 다른 글
splice(), slice() (0) | 2025.04.07 |
---|---|
shift(), unshift() (0) | 2025.04.07 |
push(), pop() (0) | 2025.04.07 |
concat()메서드 (0) | 2025.04.07 |
toString(), join() (0) | 2025.04.07 |