JS: Destructuring 解構
這幾天在複習後端和製作RESTful API,想用解構的方式把 req.body 拆成變數,再用mongoose傳入mongoDB更新資料。
例如我預期可以接收到API參數有 id, name, age, major, merit, other,所以寫了一個解構語法拆解 req.body 物件 const {id, name, age, major, merit, other} = req.body;。
假設使用者只在 name 和 age 輸入參數值,結果發現在沒有給定屬性預設值的情況下,即使...
urlun0404.hashnode.dev1 min read