j函数 判断以 什么开头

1.str.charAt(index)

 返回字符串中指定位置的字符。

 

str 是字符串  我们要将获得的数据 转化为字符串

 

var code = res.statusCode.toString();

 

 

var startChar = code.charAt(0); 
 
返回位置 为0  的  字符 
比如   ‘200’  返回的就是 2
 
 
2.  startsWith():返回布尔值,表示参数字符串是否在原字符串的头部。
 let  code  = res.statusCode;
        if(code.startsWith('2')) {
           
        }

 

 
posted @ 2019-08-01 14:56  1点  阅读(327)  评论(0编辑  收藏  举报