Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在最新的JavaScript中,这个的较短符号是什么?_Javascript_Object_Ecmascript 6 - Fatal编程技术网

在最新的JavaScript中,这个的较短符号是什么?

在最新的JavaScript中,这个的较短符号是什么?,javascript,object,ecmascript-6,Javascript,Object,Ecmascript 6,我有这个: const id = speakerRec.id; const firstName = speakerRec.firstName; const lastName = speakerRec.lastName; 我想有类似的事情,但我记不得了 const [id, firstName, lastName] = speakerRec; 它是一个对象,因此请使用对象分解(而不是数组分解): 您需要使用{}来分解对象属性: const {id, firstName, lastName} =

我有这个:

const id = speakerRec.id;
const firstName = speakerRec.firstName;
const lastName = speakerRec.lastName;
我想有类似的事情,但我记不得了

const [id, firstName, lastName] = speakerRec;

它是一个对象,因此请使用对象分解(而不是数组分解):


您需要使用
{}
来分解对象属性:

const {id, firstName, lastName} = speakerRec;
[]
用于阵列分解:

const { id, firstName, lastName } = speakerRec;
const [one, two, three] = [1, 2, 3];
演示:

const speakerRec={
id:“mySpeaker”,
名字:“杰克”,
姓:“巴什福德”
};
常量{id,firstName,lastName}=speakerRec;
console.log(id);
console.log(名字);
console.log(lastName);
常数[1,2,3]=[1,2,3];
控制台日志(一个);
控制台日志(两个);

控制台日志(三个)
{}
不是
[]
(在本例中),是否存在数组解构之类的可能重复?@Adelin并且您也可以在数组上使用对象解构,这只是有点尴尬。