扫码关注官方订阅号
今天看到这个这样一段代码
if(cc.charCodeAt(i)>10000&&ss.indexOf(cc.charAt(i))!=-1)
不是很理解,这里判断是不是等于-1有什么意义。布尔值不是只有0和1吗。。
业精于勤,荒于嬉;行成于思,毁于随。
indexOf返回所在位置,-1表示没有找到
感觉楼主没理清 括弧的层次关系。。。if(cc.charCodeAt(i)>10000&&ss.indexOf(cc.charAt(i))!=-1)
cc.charCodeAt(i)>10000
ss.indexOf(cc.charAt(i))!=-1
indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置 如果没有找到匹配的字符串则返回 -1
你需要找的是api
The indexOf() method returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex. Returns -1 if the value is not found.
indexOf,查找的时候如果返回-1,就代表没有你要找的
indexOf是按索引找元素的 如果找到该字符,则为 value 的索引位置;否则如果未找到,则为 -1索引一般是从0开始的 所以-1表示没有找到在这里 跟布尔值没有关系
http://www.w3school.com.cn/js...
js indexOf 用法
indexOf的用法中返回-1代表没有找到cc.charAt(i)这个数据。详看http://www.w3school.com.cn/js...
indexOf 查找字符串,如果找不到就返回-1,如果找到就返回值的下下标,也就是index的值
indexOf返回查找字符串所在位置,0是起始位置,-1表示没有找到
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
indexOf返回所在位置,-1表示没有找到
感觉楼主没理清 括弧的层次关系。。。
if(
cc.charCodeAt(i)>10000&&ss.indexOf(cc.charAt(i))!=-1)indexOf() 方法可返回某个指定的字符串值在字符串中首次出现的位置
如果没有找到匹配的字符串则返回 -1
你需要找的是api
The indexOf() method returns the index within the calling String object of the first occurrence of the specified value, starting the search at fromIndex. Returns -1 if the value is not found.
indexOf,查找的时候如果返回-1,就代表没有你要找的
indexOf是按索引找元素的 如果找到该字符,则为 value 的索引位置;否则如果未找到,则为 -1
索引一般是从0开始的 所以-1表示没有找到
在这里 跟布尔值没有关系
http://www.w3school.com.cn/js...
js indexOf 用法
indexOf的用法中返回-1代表没有找到cc.charAt(i)这个数据。详看http://www.w3school.com.cn/js...
indexOf 查找字符串,如果找不到就返回-1,如果找到就返回值的下下标,也就是index的值
indexOf返回查找字符串所在位置,0是起始位置,-1表示没有找到