Javascript: Rest Parameter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// rest.js
const row = {
name: "Amy",
age: 32,
email: "amy@gamil.com",
job: "cook"
};

const { job: a, none: b, ...rest_props } = row;

console.log(a); // maps to property "job"
console.log("---")
console.log(b); // property "none" doesn't exist so b is undefined
console.log("---")
console.log(rest_props); // row but without "job" property

run the code:

1
2
3
4
5
6
$ node rest.js                                                                                           
cook
---
undefined
---
{ name: 'Amy', age: 32, email: 'amy@gamil.com' }

More