text 休息参数,解构数组和对象[JavaScript]
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了text 休息参数,解构数组和对象[JavaScript]相关的知识,希望对你有一定的参考价值。
console.log('===Rest Parameters===');
function fooRest(carParam1, ...restParams)
{
console.log(carParam1);
restParams.forEach(param => console.log(param));
}
let car00 = 10;
let car01 = 20;
let car02 = 50;
fooRest(car00, car01, car02);
console.log('===Destructuring Arrays===');
let carIds = [1, 2, 3];
let [car1, car2, car3] = carIds;
console.log(car1 + ' ' + car2 + ' ' + car3);
console.log('=================');
let car4, remainingCars1;
[car4, ...remainingCars1] = carIds;
console.log(car4 + ' ' + remainingCars1[0] + ' ' + remainingCars1[1]);
console.log('=================');
let remainingCars2;
[, ...remainingCars2] = carIds;
console.log(remainingCars2[0] + ' ' + remainingCars2[1]);
console.log('===Destructuring Objects===');
let carObject = { id: 5000, style: 'convertible' };
let { id, style } = carObject;
console.log( id, style );
console.log('=================');
let carObject1 = { id1: 5000, style1: 'convertible' };
let id1, style1;
({ id1, style1 } = carObject1);
console.log( id1, style1 );
console.log('===Spread Syntax===');
function startCars(carParam1, carParam2, carParam3)
{
console.log(carParam1, carParam2, carParam3);
}
let carIds1 = [10, 20, 50];
startCars(...carIds1);
console.log('=================');
以上是关于text 休息参数,解构数组和对象[JavaScript]的主要内容,如果未能解决你的问题,请参考以下文章
在 TypeScript 中使用解构和休息的类型化函数参数
35.JavaScript对象和数组的解构赋值基础详解let陷阱函数参数解构
ES6---解构赋值(数组对象字符串数值和布尔值函数参数)
ES6/Next: 对象解构与休息 - 分组
[JavaScript]解构赋值详解
数组解构