在 ES6 中,你可以使用解构从数组和对象中提取值并赋给独特的变量。
1:解构数组中的值
const point = [10, 25, -34];
const [x, y, z] = point;
console.log(x, y, z);Prints: 10 25 -342:解构对象中的值
const gemstone = {
type: 'quartz',
color: 'rose',
karat: 21.29
};
const {type, color, karat} = gemstone;
console.log(type, color, karat);Prints: quartz rose 21.29
3万+

被折叠的 条评论
为什么被折叠?



