基本六種型別
- Nunber
- String
- Boolean
- Undefined
- Null
- Symbol
- Number
(1) toString(變為字串)
e.g.let age = 27;console.log(age.toString() +10);//** 結果就會變為字串 就會變為 2710 **//
(2)toFixed (取得某位數)
e.g.let pi = 3.1415926535;console.log(pi.toFixed(2));/*** 就會得出 3.14 ***/
2. String
(1)property(length長度)
let name= "ken";
console.log(name.length);
(2)index(索引)
從零開始計算
let name= "ken";
console.log(name[1]); //e
(3)slice(切片)
let name= "ken is good";
console.log(name.slice(1, 3)); //en
(4)indexOf (查詢index number)
let name= "ken is good";
console.log(name.indexOf(k)); //1
(5)toLowerCase(變小寫)
let name= "KEN";
console.log(name.toLowerCase()); //ken
(6)toUpperCase(變小寫)
let name= "ken";
console.log(name.toUpperCase()); //KEN
(7)split (陣列搜尋)
let name = “ken is good”;console.log(name.split(“ “)); //['ken', 'is', 'good']
//0: "ken"
//1: "is"
//2: "good"
//length: 3--------------------------------let name = “ken”;console.log(name.split(““));//['k', 'e', 'n']
//0: "k"
//1: "e"
//2: "n"
//length: 3
3. Boolean