Javascript 将结构分解为两个独立的变量

Javascript 将结构分解为两个独立的变量,javascript,ecmascript-6,Javascript,Ecmascript 6,有没有一种快速的方法来分解一个对象,使其存储到两个不同的组中?例如: const obj = {a: 1, b: 2, c:3, d: 4, e: 5}; const {a, b} = obj; // store the rest of the properties that weren't destructed above const {otherStuff} = obj; 需要注意的是: 我知道我需要对象的第一个属性是什么 我不知道还有哪些属性没有被分解 任何帮助都将不胜感激。谢谢 您可以

有没有一种快速的方法来分解一个对象,使其存储到两个不同的组中?例如:

const obj = {a: 1, b: 2, c:3, d: 4, e: 5};
const {a, b} = obj;
// store the rest of the properties that weren't destructed above
const {otherStuff} = obj;
需要注意的是:

  • 我知道我需要对象的第一个属性是什么
  • 我不知道还有哪些属性没有被分解

  • 任何帮助都将不胜感激。谢谢

    您可以使用rest参数语法的destructuring
    在另一个变量中获取对象的其余部分:

    const {a, b, ...otherStuff} = obj;
    
    constobj={a:1,b:2,c:3,d:4,e:5};
    常数{a,b,…otherStuff}=obj;
    
    console.log(其他东西)请参见对象分解