字符串方法补充
//substr(from,count) 截取 count 截取几个
//slice(from,end) 截取 不包括end
//substring(start,end) 截取 不包括end
var str = 'hello world';
var res = str.substring(1,4);
var res1 = str.slice(1,4);
console.log(str,res,res1);
//slice substring 的区别,substring的第一个参数如果为负数,依然从 0 开始,slice的第一个参数如果为负数,就是从负数位置往后截到最后,如果有第二个参数必须也为负才能使用
var res = str.substring(-1);
var res1 = str.slice(-4);
console.log(res,res1);
//charAt(index) 通过索引值,找到指定位置的字符
console.log(str.charAt(4),str[4]);
//startsWith() esdsWith() 判断字符串是否以某个字符开头和结尾的,返回值是true或false
console.log(str.startsWith('h'),str.endsWith('d'));
isNaN
// NaN : not a number 不是一个数字
//isNaN : 判断它是不是NaN
//true代表是NaN不是数字 false代表不是NaN是数字
//NaN不等于任何值,包括它本身
var a = 'a'*1; //NaN 属于 number类型
console.log(isNaN(1)); //false
console.log(isNaN(a),a,typeof(a)); //true
console.log(NaN==NaN,NaN===NaN);
//验证输入的值是否是数字
var num = prompt('请输入一串数字');
console.log(num*1,isNaN(num*1));