Repeat
-
str.repeat()코딩 이론 2023. 5. 2. 21:11
repeat() 주어진 문자열을 지정된 횟수만큼 복사하여 새 문자열을 생성할 수 있는 JavaScript의 내장 함수 str.repeat(count) str은 반복하려는 문자열 count는 반복하려는 횟수 count가 0이거나 음수일 경우에는 결과 값이 빈 문자열 count가 2^53-1보다 크거나 같은면 RangeError를 발생시킨다. 예시 const str = "hello"; const repeatedStr = str.repeat(3); console.log(repeatedStr); 콘솔에 찍히는 repeatedStr은 "hello"가 3번 반복된 새로운 문자열이므로 "hellohellohello"다 된다.