---
# System prepended metadata

title: 六角體驗營

---

六角體驗營
# 字串處理方法
* **trim()** 去除頭尾空白
* **.length** 也可用於查詢字串長度

```js=
let myEmail="    g.gmail.com" //前方有許多空白
myEmail.trim();  //頭尾空白濾掉
//g.gmail.com
```

```js=
let myname = ' Tom ';
let namelength = myname.length;
console.log(namelength); //5

namelength = myname.trim().length
console.log(namelength); //3
```

# 字串與數字轉型
* **parseInt** 字串轉為整數
```js=
let a='1';
console.log(a+1) //11 

a=parseInt(a); //1
console.log(a+1) //2
```
* **.toString()** 數字轉為字串
```js=
let b=1;
b=b.toString();
console.log(typeof b); //string
console.log(b+1); //11

```
