배열
const beasts = ['ant', 'bison', 'camel', 'duck', 'bison'];
console.log(beasts.indexOf('bison'));
// 1
// 2번 인덱스부터 찾기 시작
console.log(beasts.indexOf('bison', 2));
// 4
console.log(beasts.indexOf('giraffe'));
// -1
문자열
const paragraph = 'The quick brown fox jumps over the lazy dog. If the dog barked, was it really lazy?';
const searchTerm = 'dog';
const indexOfFirst = paragraph.indexOf(searchTerm);
console.log(`The index of the first "${searchTerm}" from the beginning is ${indexOfFirst}`);
// The index of the first "dog" from the beginning is 40
console.log(`The index of the 2nd "${searchTerm}" is ${paragraph.indexOf(searchTerm, (indexOfFirst + 1))}`);
// The index of the 2nd "dog" is 52
고생많으셨습니다!