"자바스크립트 indexOf()"의 두 판 사이의 차이

3번째 줄: 3번째 줄:
;자바스크립트 indexOf()
;자바스크립트 indexOf()


==문자열==
{{참고|자바스크립트 문자열 indexOf()}}
<syntaxhighlight lang='javascript' run>
<syntaxhighlight lang='javascript' run>
const str = "hello world hello";
const str = "hello world hello";
9번째 줄: 11번째 줄:
console.log(str.indexOf("hello", 4)); // 12
console.log(str.indexOf("hello", 4)); // 12
</syntaxhighlight>
</syntaxhighlight>
==배열==
{{참고|자바스크립트 배열 indexOf()}}
<syntaxhighlight lang='javascript' run>
<syntaxhighlight lang='javascript' run>
const arr = ["hello", "world", "hello"];
const arr = ["hello", "world", "hello"];

2023년 10월 28일 (토) 14:57 판

1 개요

JavaScript indexOf()
자바스크립트 indexOf()

2 문자열

const str = "hello world hello";
console.log(str.indexOf("hello")); // 1
console.log(str.indexOf("yellow")); // -1 (not exists)
console.log(str.indexOf("hello", 4)); // 12

3 배열

const arr = ["hello", "world", "hello"];
console.log(arr.indexOf("hello")); // 0
console.log(arr.indexOf("yellow")); // -1 (not exists)
console.log(arr.indexOf("hello", 2)); // 2

4 같이 보기

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}