How do you get all elements in array, then space them out

So basically, I tried to use this spaghetti code to get most of the elements in an array:

args[0] + args[1] + args[2] + args[3] + args[4] + args[5]
ls -r /tmp null null null

But that did not work, so I kind of need help. This is in Node (sorry, forgot to mention that)

Would something like this work?

console.log(args[0] + "<br>" + args[1] + "<br>" +  args[2] + "<br>" +  args[3] + "<br>" +  args[4] + "<br>" +  args[5]);

Oof, sorry, this is in Node, forgot to mention that.

The code above is javascript.

No, what I meant is the code this is supposed to run is in node, not the browser.

This code should run in node. The output goes to the terminal instead of the web console.

Oof, I did it, and It got all of the elements from the array, and spaced them out.

var array = ["thing 1", "thing 2", "thing 3"];
var length = array.length;
var i = 0;
var combined = ""
while (i < length){
combined = combined + " " + array[i]
i++
}
console.log(combined)

Actually,

  • If you’re running console.log("") in client-side code (similar to ~hello-webpage), it appears in your browser’s DevTools.

  • If you’re running console.log("") in server-side code and npm start is automatically run by Glitch every time you make updates, then it shows up in Logs.

  • If you’re running console.log("") in server-side code and you’re running npm start manually in the Terminal, then you’ll get the output in the Terminal itself.

1 Like
const myArrayString = myArray.join(" ");
Documentation link

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join

1 Like