1、返回一个新字符串,表示将原字符串重复n次。如果参数为小数,则会被取整。
console.log('abc'.repeat(1.6)) //abc
2、如果为负数或者Infinity,会报错。
console.log('abc'.repeat(-1)) // RangeError console.log('abc'.repeat(Infinity)) // RangeError
3、如果参数是0到-1之间的小数或者NaN,则等同于0。
console.log('abc'.repeat(-0.1)) // console.log('abc'.repeat(NaN)) //
一般来说,str.repeat(n)重复字符串n遍,括号内填重复的遍数。
以上就是js中repeat()的使用,希望对大家有所帮助。更多js学习指路:
推荐操作环境:windows7系统、jquery3.2.1版本,DELL G3电脑。
Copyright © 2019- net188.cn 版权所有 湘ICP备2022005869号-2
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务