ES6 中新增的字符串函数
打赏作者

jayin

·‘哈’.repeat(100)·

xw716825

姐姐是四川的?

raytimmer

声音好听,且幽默,尤其是‘哈’.repeat(5)的时候

xianyunyh

哈哈哈哈哈

“哈”.repeat(5) startWith()
endWith()

luzhongyang

function padder()完整的函数写法是什么,后面看不完整啊

goodawei

const heading = ${'='.repeat(5)} ${fan} ${'='.repeat(5)};

	function padder(string,length=25){
		return `${''.repeat(Math.max(length - string.length, 0))}${string}`
	}

	console.log(padder(id));
	console.log(padder(fan));

	//*看不出是那的问题,视频和我的代码是一样的啊,视频是有对齐,我是左对齐。头疼。。。
acheng93 回复 goodawei

return ${' '.repeat(Math.max(length - string.length, 0))}${string}
注意是有个空格的字符串

xd100 回复 acheng93

ffffddddtest

maomao4rv

哈哈的我浑身鸡皮疙瘩

xuezhiwen

最后那个,我的也是左对齐

duo

笔记:

<script type="text/javascript">
		const id = '15212619000504093X';
		const fan = 'I love vegetables.';
		const heading = `${'='.repeat(5)} ${fan} ${'='.repeat(5)}`;

		console.log(heading);//美化字符串

		//.startsWith()
		//id.startsWith('15')
		//id.startsWith('1900',6)
		//大小写敏感fan.startsWith('I')

		//.endsWith()
		//id.endsWith('X')
		//fan.endsWith('love',6)

		//.includes()
		//以前的用法fan.indexOf('vegetables')!= -1
		//fan.includes('vegetables')
		//fan.includes('veg',10)

		//.repeat()重复
		//'ha'.repeat(5)
	</script>
xd100 回复 duo

棒哦ffffffffff