获取 javascript 中对象的值

get value of object in javascript

我试着看懂下面的代码(可以复制到ES 6 Console

myarr = [{id:'1',title:'title1'},{id:'2',title:'title2'}] ;
mystate = { allVotes: myarr };
console.log(mystate);

const { allVotes } = mystate; //This line I do not understand
console.log(allVotes);

const { allVotes } = mystate; 

似乎是一种设置变量的快捷方式,其中键的名称填充了对象中的值。有人可以解释一下吗?我会做得更丑陋:

const allVotes2 = mystate['allVotes'];

它被称为解构赋值,您可以在这里阅读:https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment