웹 프로그래밍 기초/객체

repeat()

별초롱언니 2025. 4. 9. 16:58

문자열을 인수로 전달받은 정수만큼 반복해 연결하여 새로운 문자열을 반환한다. 

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    let str = "abc";

    document.write(str.repeat(1) + "<br>");
    document.write(str.repeat() + "<br>");
    document.write(str.repeat(2) + "<br>");
    document.write(str.repeat(2.5) + "<br>");
    document.write(str.repeat(-1) + "<br>");
  </script>
</body>
</html>

'웹 프로그래밍 기초 > 객체' 카테고리의 다른 글

get메서드 / set메서드  (0) 2025.04.09
내장 객체 (Date)  (0) 2025.04.09
trim()  (0) 2025.04.09
split()  (1) 2025.04.09
replace()  (0) 2025.04.09