使用for…of代替for循环:
var string = 'string'for(var i of string) {console.log(i)}
includes(),startsWidth(),endsWidth()
不用使用indexOf()判断字符串中是否包含某个值了,使用includes():
var string = 'string'string.includes('i', 0) // true
includes第二个参数表示查找的起始索引。还可以使用startsWidth()和endsWidth()判断字符串是否以某些字符开始或结尾。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号