Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Christopher Debove
PLUS
Christopher Debove
Courses Plus Student 18,372 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.

nico dev
nico dev
20,364 Points

Elegant solution, though!

Kenneth Kim
Kenneth Kim
3,795 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
Courses Plus Student 18,372 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