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

4번째 줄: 4번째 줄:


<syntaxhighlight lang='javascript' run>
<syntaxhighlight lang='javascript' run>
console.log("hello world hello".indexOf("hello")); // 1
const str = "hello world hello";
console.log("hello world hello".indexOf("yellow")); // -1 (not exists)
console.log(str.indexOf("hello")); // 1
console.log("hello world hello".indexOf("hello", 4)); // 12
console.log(str.indexOf("yellow")); // -1 (not exists)
console.log(str.indexOf("hello", 4)); // 12
</syntaxhighlight>
<syntaxhighlight lang='javascript' run>
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
</syntaxhighlight>
</syntaxhighlight>



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

1 개요

JavaScript indexOf()
자바스크립트 indexOf()
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
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

2 같이 보기

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