[筆記] get a subset of object in js with destructuring
```javascript
/*
let res = await axios.get("/api/xxx");
let data = res.data;
*/
let data = {
name: "t510599",
username: "t510599",
fetchTime: 1596816362612,
status: true
}
// we need only name and username
vm.data = (({name, username}) => ({name,username}))(data);
```
Reference:
- https://stackoverflow.com/questions/17781472/how-to-get-a-subset-of-a-javascript-objects-properties
- https://www.digitalocean.com/community/tutorials/understanding-destructuring-rest-parameters-and-spread-syntax-in-javascript
2020-08-08 00:08:07
留言
Last fetch: --:--
現在還沒有留言!