---
# System prepended metadata

title: 1. Javascript 邏輯判斷
tags: [Javascript]

---

###### tags: `Javascript`

# 1. Javascript 邏輯判斷

## == v.s === 
- 兩個等於:協助轉型 三個等於:會比較型別

## if else_if else 
- 最後的else可以填入輸入資料不正確
---

# 2. Javascript 陣列

## 陣列基本操作
- 陣列宣告
```javascript=
let colors = ['red','green','blue']
```
- 陣列基本操作

| Method |purpose|instance | value |
| -------- | -------- | -------- |-------|
| length   |檢查長度|colors.length     | 3    |
|push|塞東西到陣列尾|colors.push("X")|['red','green','blue','X']|
|unshift|塞東西到陣列首|colors.unshift('X')|['X','red','green','blue']|
|pop|刪掉陣列尾|colors.pop()|['red','green']|
|shift|刪掉陣列首|colors.shift()|['green','blue']|
|splice|第一個數字:起始位置,第二個數字:刪除幾筆|colors.shift(0,2)|['blue']|

# 3. Javascript 物件

## 物件新增
```javascript=
    home.name ="小明"
    home.num = 3
```

## delete 物件刪除
```javascript=
let home= {
    mother:"Mary",
    dad:"Tom",
    sister:"Angle",
    dog:"mos",
    people:3
};
//刪除狗狗
delete home.dog;
```
## (A) home.dog (B) home['dog'] 兩種物件讀取的方式
```javascript=
let home= {
    mother:"Mary",
    dad:"Tom",
    sister:"Angle",
    dog:"mos",
    people:3
};
//以下為兩種讀取方式
console.log(home.dog,home['dog'])
```

# 4. Javascript 物件與陣列混用
## 陣列裡面有物件
```javascript=
let market = [
    {
        bossName ="tom",
        staffNum = 3
    },
    {
        bossName ="andy",
        staffNum = 4
    };
]
//尋找混合物件
console.log(market[0].bossName);
```
## 陣列裡面的物件包物件
```javascript=
let market = [
        {
             bossStatus:{
                bossName:'Amy',
                bossAge:19,
                bossSex:'Female'
            },
            staffNum:20
        },
        {
            bossStatus:{
                bossName:'Andy',
                bossAge:45,
                bossSex:'Male'
            },
            staffNum:6
        }
]
```
---

