JavaScript Node.js Basics Building a Command Line Application Capturing Command Line Arguments

Christopher Debove
PRO
Christopher Debove
Pro Student 18,321 Points

Could have use destructuring

In the video when we get the arguments from command line. Couldn't we not have use the destructuring?

const [,, ...users] = process.argv

in place of

const users = process.argv.slice(2);

3 Answers

Yes, but I don't think destructuring was available in Node when this video was first made.

Christopher Debove
PRO
Christopher Debove
Pro Student 18,321 Points

Ow ok ! Thanks for the answer. Should have look at this.

Nico Trivelli
Nico Trivelli
20,353 Points

Elegant solution, though!

Kenneth Kim
Kenneth Kim
3,794 Points

Hi, can anyone please explain what "const [,, ...users] = process.argv" does as mention by Christopher? Is this a new syntax in ES2015? I'm not quite familiar with it yet. Thanks

Christopher Debove
Christopher Debove
Pro Student 18,321 Points

Yeah it is a new syntax of ES2015.

let [a, b, c] = [1, 2, 3]; // a = 1, b = 2, c = 3
let [a,, b] = [1, 2, 3]; // a = 1, b = 3