자바스크립트 indexOf()

Jmnote (토론 | 기여)님의 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 }}