---
# System prepended metadata

title: JS object(二)

---

# JS object(二)

當key跟value一樣時可以省略

```javascript
let age = 18
let attack = 100

const hero = {
    name:  "kk",
    age: age ,
    attack: attack,
}
```

```javascript
let age = 18
let attack = 100
const hero = {
    name:  "kk",
    age,
    attack,
}
```
#
解構

```javascript
const obj ={
    age: 123,
    power:456,
}
const age = obj.age
const power = obj.power
```
解構寫法，一樣的效果
```javascript
const obj ={
    age: 123,
    power:456,
}
const { age , power } = obj
```
const { age , power } = obj 這一行就可以達到上面兩行的效果

＃
```javascript
function bmi(someone){
    console.log(someone.height);
    console.log(someone.weigjt);
}
const hero = {
    height: 180 ,
    weight: 70,
    age: 20
}
```

```javascript
function bmi({height,  weight}){
    console.log(height);
    console.log(weight);
}
const hero = {
    height: 180 ,
    weight: 70,
    age: 20
}
```

