메소드2 [Javascript 기초] 문자열 내장함수 문자열 내장함수 1. String.length 2. String.indexOf() 3. String.slice() 4. String.substr() 5. String.replace() 6. String.split() 1. String.length String.length는 문자열의 길이를 반환해 주는 속성입니다. (메소드 x) const txt = "Hello World"; console.log(txt.length); // 11 2. String.indexOf() String.indexOf()는 찾고자 하는 문자열의 위치를 반환해 줍니다. 주로 해당 문자가 포함돼 있는 지 탐색할 때 사용합니다. (포함돼 있지 않으면 -1 출력) const txt = "Hello World"; console.log(txt.. 2023. 5. 17. [Javascript 기초] forEach(), map() 메소드 1. forEach() 메소드 forEach() 메소드는 배열의 요소를 반복하여 함수를 호출하며, 배열에서 루프를 돌 때 사용합니다. forEach() 메소드는 ES5 문법이며, 반복 처리가 가능하고 DOM 반복이 가능한 유사배열입니다. forEach() 메소드의 문법은 다음과 같습니다. colors.forEach((currentValue, index, arr)); currentValue: 배열의 값 index: 현재 항목의 인덱스(선택사항) arr: 현재 항목의 배열(선택사항) const colors = ["black", "red", "blue"]; colors.forEach((currentValue, index, arr)=>{ console.log(currentValue); // 배열값 console.. 2023. 5. 9. 이전 1 다음