2019-12-27


字符串处理方法

var str = '2019-12-27';

var arr = str.split('-');//将-切掉['2019','12','27']

var arr2 = str.split('');//将每个字符分开['2','0','1','9','1','2','2','7']

var str2 = '#div1';

var str3 = '.div1';

var str4 = 'str2.charAt(0)';//#

if (str4 == '#'){

console.log('id选择器');

}

var str5 = 'Microsoft Yahei';

var num = str5.indexOf('Yahei');//10

var num2 = str5.indexOf('xihei');//-1

var str6 = str5.substring(10,15);//从10开始从15结束 包括开始不包括结束Yahei

var str6 = str5.substring(10);//从10开始到结尾Yahei

console.log(str6.toUpperCase());//全转大写YAHEI

console.log(str6.toLowerCase());//全转小写 yahei

字符串反转

1、split字符串转成数组

2、reverse数组反转

3、join数组转成字符串

var sTr = '123asd7988asdfe21';

var str2 = sTr.split('').reverse().join('');//12efdsa8897dsa321

console.log(str2)

你可能感兴趣的:(2019-12-27)