js的幾個(gè)簡(jiǎn)單函數(shù)
1.toFixed(n)函數(shù),四舍五入保留n位小數(shù)點(diǎn)
var a = 133.55644444;
var b = a.toFixed(2);//133.56
2.parseInt(n)函數(shù),字符串轉(zhuǎn)成整數(shù)
parseInt('dd');//NaN
parseInt('334.55');//334
3.parseFloat(n)函數(shù),字符串轉(zhuǎn)成浮點(diǎn)數(shù)
parseFloat('gg');//NaN
parseFloat('456.46');//456.46
4.split函數(shù),字符串轉(zhuǎn)數(shù)組函數(shù)
var s = "dffd,gfg,gfg";
s.split(',');//["dffd", "gfg", "gfg"]
5.join函數(shù),數(shù)組轉(zhuǎn)字符串
var t = ["dffd", "gfg", "gfg"];
t.join(',')//"dffd,gfg,gfg"
6.length函數(shù),獲取字符串長度;
var s = "45455";
s.length;//5
7.indexOf函數(shù),判斷字串在目標(biāo)串中第一次出現(xiàn)的位置
var s = "12346";
s.indexOf('23');//1
s.indexOf('235');//-1
s.indexOf('123');//0
8.lastIndexOf函數(shù),判斷字串在目標(biāo)串中最后一次出現(xiàn)的位置
var s = '1234532422';
s.lastIndexOf('2');//9
9.replace函數(shù),替換字符串
var s = '1234562452';
s.replace('2','a');//1a34562452
10.toUpperCase函數(shù),字符串轉(zhuǎn)成大寫
var s = 'aaasd';
s.toUpperCase();//'AAASD'
11.toLowerCase函數(shù),字符串轉(zhuǎn)成小寫
var s = 'AAASD';
s.toLowerCase();//'aaasd'