码迷,mamicode.com
首页 > 其他好文 > 详细

TypeScript之解构赋值

时间:2018-05-20 10:43:20      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:.com   string   name   err   bubuko   分享   pes   types   []   

一 数组的解构赋值

 

const heroes: string[] = [];
const turtles: string[] = [‘Leo‘, ‘Raph‘, ‘Mikey‘, ‘Don‘];
console.log(...turtles);
heroes.push(...turtles);
console.log(heroes);

 

技术分享图片

 

 二 对象的结构赋值

 

const name = ‘iPhone‘;
const color = ‘gold‘;
console.log(JSON.stringify({ name, color }));

 

技术分享图片

 

const phone = {
  name: ‘iPhone‘,
  color: ‘gold‘
};

const car = {
  name: ‘Ferrari‘,
  color: ‘red‘
};

console.log(JSON.stringify({ phone, car }));

 

技术分享图片

 

TypeScript之解构赋值

标签:.com   string   name   err   bubuko   分享   pes   types   []   

原文地址:https://www.cnblogs.com/sea-breeze/p/9062468.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!