0

假设我正在定义一系列变量,如下所示:

let test = {one:1, two:2, three:3}
let {one, two, three} = test

这将使用变量中的相应值定义变量onetwo和。现在说我想将所有值定义为变量,但我不知道其中的元素。我怎么能那样做?threetesttest

到目前为止,我已经尝试在其中使用一个数组,例如

let {["one", "two", "three"]} = test

但我收到错误

let {["one", "two", "three"]} = test
           ^

Uncaught SyntaxError: Unexpected token ','

然后我首先尝试使用扩展运算符

let {...["one", "two", "three"]} = test

但这也不起作用并且有同样的错误。

我完全不知道从这里继续。

4

0 回答 0