JavaScript/메소드
[javascript] 문자열 포함여부 확인하기 indexOf(), includes()
Angry Stock
2023. 8. 7. 16:38
반응형
function solution1(string1, target) {
return string1.indexOf(target);
}
function solution2(string2, target) {
return string2.includes(target);
}
let string1 = 'strawberry';
let string2 = 'peach';
let target = ['berry', 'pea'];
for (let i = 0; i < target.length; i++) {
console.log('solution1', solution1(string1, target[i]));
console.log('solution2', solution2(string2, target[i]));
}
결과
반응형