gpt4 book ai didi

ecmascript-6 - 将对象的子集直接解构为新对象

转载 作者:行者123 更新时间:2023-12-04 17:57:24 26 4
gpt4 key购买 nike

<分区>

是否有一个我正在空白的单行代码来执行此操作?

// this.state is a basic object with many keys
var {toDate, fromDate, location, flavor} = this.state
var goodKeys = {toDate, fromDate, location, flavor}
// goodKeys is an object that contains a subset of this.state's keys

我能想到的唯一方法是:

var {keyIDontWant, otherUnwanted, ...goodKeys} = this.state

但这似乎会让阅读代码的人感到困惑,并且需要更多的努力来弄清楚如何编写。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com