A new method string - repeat ()

repeatMethod returns a new string that represents the original string is repeated ntwice.

"abc".repeat(-1)     // RangeError: repeat count must be positive and less than inifinity
"abc".repeat(0)      // ""
"abc".repeat(1)      // "abc"
"abc".repeat(2)      // "abcabc"
"abc".repeat(3.5)    // "abcabcabc" 参数count将会被自动转换成整数.
"abc".repeat(1/0)    // RangeError: repeat count must be positive and less than inifinity

  

Guess you like

Origin www.cnblogs.com/blogZhao/p/12554906.html