반응형 includes()1 [javascript] 문자열 포함여부 확인하기 indexOf(), includes() 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])); } 결과 2023. 8. 7. 이전 1 다음 반응형