Sean Flood13,370 Points
Why are you joining the spaces in the query?
Just wondering what the purpose of the
const query = process.argv.slice(2).join(' ');
Im sure an explanation will explain it properly but can anyone show me an example of whats being joined and why?
Steven Parker179,664 Points
In the video, the "join" uses and underscore ("_") instead of a space, but the concept is the same.
The special object attribute "process.argv" stores the terms that were used on the command line in an array, and "slice" with an argument of 2 removes the first two terms and returns the rest. So if the program was started with the command "node myprogram Cleveland Ohio", then the slice would return the array:
["Cleveland", "Ohio"]. Then the "join" converts the array into a single string, which in this case would be "Cleveland Ohio" (the one in the video would make "Cleveland _Ohio").